@@ -12,7 +12,7 @@ class CachedBuilder extends EloquentBuilder
12
12
13
13
public function avg ($ column )
14
14
{
15
- if (! $ this ->isCachable ) {
15
+ if (! $ this ->isCachable () ) {
16
16
return parent ::avg ($ column );
17
17
}
18
18
@@ -25,7 +25,7 @@ public function avg($column)
25
25
26
26
public function count ($ columns = ['* ' ])
27
27
{
28
- if (! $ this ->isCachable ) {
28
+ if (! $ this ->isCachable () ) {
29
29
return parent ::count ($ columns );
30
30
}
31
31
@@ -38,7 +38,7 @@ public function count($columns = ['*'])
38
38
39
39
public function cursor ()
40
40
{
41
- if (! $ this ->isCachable ) {
41
+ if (! $ this ->isCachable () ) {
42
42
return collect (parent ::cursor ());
43
43
}
44
44
@@ -62,20 +62,20 @@ public function delete()
62
62
*/
63
63
public function find ($ id , $ columns = ['* ' ])
64
64
{
65
- if (! $ this ->isCachable ) {
65
+ if (! $ this ->isCachable () ) {
66
66
return parent ::find ($ id , $ columns );
67
67
}
68
68
69
69
$ arguments = func_get_args ();
70
- $ cacheKey = $ this ->makeCacheKey ($ columns );
70
+ $ cacheKey = $ this ->makeCacheKey ([ ' * ' ], null , " -find_ { $ id }" );
71
71
$ method = 'find ' ;
72
72
73
73
return $ this ->cachedValue ($ arguments , $ cacheKey , $ method );
74
74
}
75
75
76
76
public function first ($ columns = ['* ' ])
77
77
{
78
- if (! $ this ->isCachable ) {
78
+ if (! $ this ->isCachable () ) {
79
79
return parent ::first ($ columns );
80
80
}
81
81
@@ -88,7 +88,7 @@ public function first($columns = ['*'])
88
88
89
89
public function get ($ columns = ['* ' ])
90
90
{
91
- if (! $ this ->isCachable ) {
91
+ if (! $ this ->isCachable () ) {
92
92
return parent ::get ($ columns );
93
93
}
94
94
@@ -101,7 +101,7 @@ public function get($columns = ['*'])
101
101
102
102
public function max ($ column )
103
103
{
104
- if (! $ this ->isCachable ) {
104
+ if (! $ this ->isCachable () ) {
105
105
return parent ::max ($ column );
106
106
}
107
107
@@ -114,7 +114,7 @@ public function max($column)
114
114
115
115
public function min ($ column )
116
116
{
117
- if (! $ this ->isCachable ) {
117
+ if (! $ this ->isCachable () ) {
118
118
return parent ::min ($ column );
119
119
}
120
120
@@ -125,9 +125,27 @@ public function min($column)
125
125
return $ this ->cachedValue ($ arguments , $ cacheKey , $ method );
126
126
}
127
127
128
+ public function paginate (
129
+ $ perPage = null ,
130
+ $ columns = ['* ' ],
131
+ $ pageName = 'page ' ,
132
+ $ page = null
133
+ ) {
134
+ if (! $ this ->isCachable ()) {
135
+ return parent ::paginate ($ perPage , $ columns , $ pageName , $ page );
136
+ }
137
+
138
+ $ arguments = func_get_args ();
139
+ $ page = $ page ?: 1 ;
140
+ $ cacheKey = $ this ->makeCacheKey ($ columns , null , "-paginate_by_ {$ perPage }_ {$ pageName }_ {$ page }" );
141
+ $ method = 'paginate ' ;
142
+
143
+ return $ this ->cachedValue ($ arguments , $ cacheKey , $ method );
144
+ }
145
+
128
146
public function pluck ($ column , $ key = null )
129
147
{
130
- if (! $ this ->isCachable ) {
148
+ if (! $ this ->isCachable () ) {
131
149
return parent ::pluck ($ column , $ key );
132
150
}
133
151
@@ -141,7 +159,7 @@ public function pluck($column, $key = null)
141
159
142
160
public function sum ($ column )
143
161
{
144
- if (! $ this ->isCachable ) {
162
+ if (! $ this ->isCachable () ) {
145
163
return parent ::sum ($ column );
146
164
}
147
165
@@ -154,7 +172,7 @@ public function sum($column)
154
172
155
173
public function value ($ column )
156
174
{
157
- if (! $ this ->isCachable ) {
175
+ if (! $ this ->isCachable () ) {
158
176
return parent ::value ($ column );
159
177
}
160
178
@@ -197,7 +215,9 @@ protected function preventHashCollision(
197
215
string $ method
198
216
) {
199
217
if ($ result ['key ' ] !== $ cacheKey ) {
200
- cache ()->tags ($ cacheTags )->forget ($ hashedCacheKey );
218
+ $ this ->cache ()
219
+ ->tags ($ cacheTags )
220
+ ->forget ($ hashedCacheKey );
201
221
202
222
$ result = $ this ->retrieveCachedValue (
203
223
$ arguments ,
0 commit comments