@@ -12,7 +12,7 @@ class CachedBuilder extends EloquentBuilder
1212
1313 public function avg ($ column )
1414 {
15- if (! $ this ->isCachable ) {
15+ if (! $ this ->isCachable () ) {
1616 return parent ::avg ($ column );
1717 }
1818
@@ -25,7 +25,7 @@ public function avg($column)
2525
2626 public function count ($ columns = ['* ' ])
2727 {
28- if (! $ this ->isCachable ) {
28+ if (! $ this ->isCachable () ) {
2929 return parent ::count ($ columns );
3030 }
3131
@@ -38,7 +38,7 @@ public function count($columns = ['*'])
3838
3939 public function cursor ()
4040 {
41- if (! $ this ->isCachable ) {
41+ if (! $ this ->isCachable () ) {
4242 return collect (parent ::cursor ());
4343 }
4444
@@ -62,20 +62,20 @@ public function delete()
6262 */
6363 public function find ($ id , $ columns = ['* ' ])
6464 {
65- if (! $ this ->isCachable ) {
65+ if (! $ this ->isCachable () ) {
6666 return parent ::find ($ id , $ columns );
6767 }
6868
6969 $ arguments = func_get_args ();
70- $ cacheKey = $ this ->makeCacheKey ($ columns );
70+ $ cacheKey = $ this ->makeCacheKey ([ ' * ' ], null , " -find_ { $ id }" );
7171 $ method = 'find ' ;
7272
7373 return $ this ->cachedValue ($ arguments , $ cacheKey , $ method );
7474 }
7575
7676 public function first ($ columns = ['* ' ])
7777 {
78- if (! $ this ->isCachable ) {
78+ if (! $ this ->isCachable () ) {
7979 return parent ::first ($ columns );
8080 }
8181
@@ -88,7 +88,7 @@ public function first($columns = ['*'])
8888
8989 public function get ($ columns = ['* ' ])
9090 {
91- if (! $ this ->isCachable ) {
91+ if (! $ this ->isCachable () ) {
9292 return parent ::get ($ columns );
9393 }
9494
@@ -101,7 +101,7 @@ public function get($columns = ['*'])
101101
102102 public function max ($ column )
103103 {
104- if (! $ this ->isCachable ) {
104+ if (! $ this ->isCachable () ) {
105105 return parent ::max ($ column );
106106 }
107107
@@ -114,7 +114,7 @@ public function max($column)
114114
115115 public function min ($ column )
116116 {
117- if (! $ this ->isCachable ) {
117+ if (! $ this ->isCachable () ) {
118118 return parent ::min ($ column );
119119 }
120120
@@ -125,9 +125,27 @@ public function min($column)
125125 return $ this ->cachedValue ($ arguments , $ cacheKey , $ method );
126126 }
127127
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+
128146 public function pluck ($ column , $ key = null )
129147 {
130- if (! $ this ->isCachable ) {
148+ if (! $ this ->isCachable () ) {
131149 return parent ::pluck ($ column , $ key );
132150 }
133151
@@ -141,7 +159,7 @@ public function pluck($column, $key = null)
141159
142160 public function sum ($ column )
143161 {
144- if (! $ this ->isCachable ) {
162+ if (! $ this ->isCachable () ) {
145163 return parent ::sum ($ column );
146164 }
147165
@@ -154,7 +172,7 @@ public function sum($column)
154172
155173 public function value ($ column )
156174 {
157- if (! $ this ->isCachable ) {
175+ if (! $ this ->isCachable () ) {
158176 return parent ::value ($ column );
159177 }
160178
@@ -197,7 +215,9 @@ protected function preventHashCollision(
197215 string $ method
198216 ) {
199217 if ($ result ['key ' ] !== $ cacheKey ) {
200- cache ()->tags ($ cacheTags )->forget ($ hashedCacheKey );
218+ $ this ->cache ()
219+ ->tags ($ cacheTags )
220+ ->forget ($ hashedCacheKey );
201221
202222 $ result = $ this ->retrieveCachedValue (
203223 $ arguments ,
0 commit comments