@@ -94,14 +94,12 @@ protected function getWhereClauses(array $wheres = []) : string
94
94
}
95
95
96
96
$ value = array_get ($ where , 'value ' );
97
-
98
- if (in_array ($ where ['type ' ], ['In ' , 'Null ' , 'NotNull ' ])) {
99
- $ value = strtolower ($ where ['type ' ]);
100
- }
101
-
102
- if (is_array (array_get ($ where , 'values ' ))) {
103
- $ value .= '_ ' . implode ('_ ' , $ where ['values ' ]);
104
- }
97
+ $ value .= in_array ($ where ['type ' ], ['In ' , 'Null ' , 'NotNull ' ])
98
+ ? strtolower ($ where ['type ' ])
99
+ : '' ;
100
+ $ value .= is_array (array_get ($ where , 'values ' ))
101
+ ? '_ ' . implode ('_ ' , $ where ['values ' ])
102
+ : '' ;
105
103
106
104
return "{$ carry }- {$ where ['column ' ]}_ {$ value }" ;
107
105
}) ?: '' ;
@@ -126,6 +124,16 @@ protected function getOrderByClauses(){
126
124
});
127
125
}
128
126
127
+ protected function getMethodKey (string $ postfix = null ) : string
128
+ {
129
+ return str_slug (get_class ($ this ->model )) . $ postfix ;
130
+ }
131
+
132
+ protected function getModelTag () : array
133
+ {
134
+ return [str_slug (get_class ($ this ->model ))];
135
+ }
136
+
129
137
protected function getCacheTags () : array
130
138
{
131
139
return collect ($ this ->eagerLoad )->keys ()
@@ -152,33 +160,24 @@ protected function getCacheTags() : array
152
160
153
161
public function avg ($ column )
154
162
{
155
- $ tags = [str_slug (get_class ($ this ->model ))];
156
- $ key = str_slug (get_class ($ this ->model )) ."-avg_ {$ column }" ;
157
-
158
- return $ this ->cache ($ tags )
159
- ->rememberForever ($ key , function () use ($ column ) {
163
+ return $ this ->cache ($ this ->getModelTag ())
164
+ ->rememberForever ($ this ->getMethodKey ("-avg_ {$ column }" ), function () use ($ column ) {
160
165
return parent ::avg ($ column );
161
166
});
162
167
}
163
168
164
169
public function count ($ columns = ['* ' ])
165
170
{
166
- $ tags = [str_slug (get_class ($ this ->model ))];
167
- $ key = str_slug (get_class ($ this ->model )) ."-count " ;
168
-
169
- return $ this ->cache ($ tags )
170
- ->rememberForever ($ key , function () use ($ columns ) {
171
+ return $ this ->cache ($ this ->getModelTag ())
172
+ ->rememberForever ($ this ->getMethodKey ("-count " ), function () use ($ columns ) {
171
173
return parent ::count ($ columns );
172
174
});
173
175
}
174
176
175
177
public function cursor ()
176
178
{
177
- $ tags = [str_slug (get_class ($ this ->model ))];
178
- $ key = str_slug (get_class ($ this ->model )) ."-cursor " ;
179
-
180
- return $ this ->cache ($ tags )
181
- ->rememberForever ($ key , function () {
179
+ return $ this ->cache ($ this ->getModelTag ())
180
+ ->rememberForever ($ this ->getMethodKey ("-cursor " ), function () {
182
181
return collect (parent ::cursor ());
183
182
});
184
183
}
@@ -188,81 +187,62 @@ public function cursor()
188
187
*/
189
188
public function find ($ id , $ columns = ['* ' ])
190
189
{
191
- $ tags = $ this ->getCacheTags ();
192
- $ key = $ this ->getCacheKey ($ columns , $ id );
193
-
194
- return $ this ->cache ($ tags )
195
- ->rememberForever ($ key , function () use ($ id , $ columns ) {
190
+ return $ this ->cache ($ this ->getCacheTags ())
191
+ ->rememberForever ($ this ->getCacheKey ($ columns , $ id ), function () use ($ id , $ columns ) {
196
192
return parent ::find ($ id , $ columns );
197
193
});
198
194
}
199
195
200
196
public function first ($ columns = ['* ' ])
201
197
{
202
- $ tags = $ this ->getCacheTags ();
203
- $ key = $ this ->getCacheKey ($ columns ) . '-first ' ;
204
-
205
- return $ this ->cache ($ tags )
206
- ->rememberForever ($ key , function () use ($ columns ) {
198
+ return $ this ->cache ($ this ->getCacheTags ())
199
+ ->rememberForever ($ this ->getCacheKey ($ columns ) . '-first ' , function () use ($ columns ) {
207
200
return parent ::first ($ columns );
208
201
});
209
202
}
210
203
211
204
public function get ($ columns = ['* ' ])
212
205
{
213
- $ tags = $ this ->getCacheTags ();
214
- $ key = $ this ->getCacheKey ($ columns );
215
-
216
- return $ this ->cache ($ tags )
217
- ->rememberForever ($ key , function () use ($ columns ) {
206
+ return $ this ->cache ($ this ->getCacheTags ())
207
+ ->rememberForever ($ this ->getCacheKey ($ columns ), function () use ($ columns ) {
218
208
return parent ::get ($ columns );
219
209
});
220
210
}
221
211
222
212
public function max ($ column )
223
213
{
224
- $ tags = [str_slug (get_class ($ this ->model ))];
225
- $ key = str_slug (get_class ($ this ->model )) ."-max_ {$ column }" ;
226
-
227
- return $ this ->cache ($ tags )
228
- ->rememberForever ($ key , function () use ($ column ) {
214
+ return $ this ->cache ($ this ->getModelTag ())
215
+ ->rememberForever ($ this ->getMethodKey ("-max_ {$ column }" ), function () use ($ column ) {
229
216
return parent ::max ($ column );
230
217
});
231
218
}
232
219
233
220
public function min ($ column )
234
221
{
235
- $ tags = [str_slug (get_class ($ this ->model ))];
236
- $ key = str_slug (get_class ($ this ->model )) ."-min_ {$ column }" ;
237
-
238
- return $ this ->cache ($ tags )
239
- ->rememberForever ($ key , function () use ($ column ) {
222
+ return $ this ->cache ($ this ->getModelTag ())
223
+ ->rememberForever ($ this ->getMethodKey ("-min_ {$ column }" ), function () use ($ column ) {
240
224
return parent ::min ($ column );
241
225
});
242
226
}
243
227
244
228
public function pluck ($ column , $ key = null )
245
229
{
246
- $ tags = $ this ->getCacheTags ();
247
230
$ cacheKey = $ this ->getCacheKey ([$ column ]) . "-pluck_ {$ column }" ;
248
231
249
232
if ($ key ) {
250
233
$ cacheKey .= "_ {$ key }" ;
251
234
}
252
235
253
- return $ this ->cache ($ tags )
236
+ return $ this ->cache ($ this -> getCacheTags () )
254
237
->rememberForever ($ cacheKey , function () use ($ column , $ key ) {
255
238
return parent ::pluck ($ column , $ key );
256
239
});
257
240
}
258
241
259
242
public function sum ($ column )
260
243
{
261
- $ tags = [str_slug (get_class ($ this ->model ))];
262
- $ key = str_slug (get_class ($ this ->model )) ."-sum_ {$ column }" ;
263
-
264
- return $ this ->cache ($ tags )
265
- ->rememberForever ($ key , function () use ($ column ) {
244
+ return $ this ->cache ($ this ->getModelTag ())
245
+ ->rememberForever ($ this ->getMethodKey ("-sum_ {$ column }" ), function () use ($ column ) {
266
246
return parent ::sum ($ column );
267
247
});
268
248
}
0 commit comments