1 | <?php |
||
23 | trait CacheableEloquent |
||
24 | { |
||
25 | /** |
||
26 | * The IoC container instance. |
||
27 | * |
||
28 | * @var \Illuminate\Contracts\Container\Container |
||
29 | */ |
||
30 | protected static $container; |
||
31 | |||
32 | /** |
||
33 | * The methods to clear cache on. |
||
34 | * |
||
35 | * @var array |
||
36 | */ |
||
37 | protected static $cacheClearOn = [ |
||
38 | 'create', |
||
39 | 'update', |
||
40 | 'delete', |
||
41 | ]; |
||
42 | |||
43 | /** |
||
44 | * Indicate if the model cache clear is enabled. |
||
45 | * |
||
46 | * @var bool |
||
47 | */ |
||
48 | protected static $cacheClearEnabled = true; |
||
49 | |||
50 | /** |
||
51 | * The model cache driver. |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $cacheDriver; |
||
56 | |||
57 | /** |
||
58 | * The model cache lifetime. |
||
59 | * |
||
60 | * @var float|int |
||
61 | */ |
||
62 | protected $cacheLifetime = -1; |
||
63 | |||
64 | /** |
||
65 | * Register an updated model event with the dispatcher. |
||
66 | * |
||
67 | * @param \Closure|string $callback |
||
68 | * @param int $priority |
||
69 | * |
||
70 | * @return void |
||
71 | */ |
||
72 | abstract public static function updated($callback, $priority = 0); |
||
73 | |||
74 | /** |
||
75 | * Register a created model event with the dispatcher. |
||
76 | * |
||
77 | * @param \Closure|string $callback |
||
78 | * @param int $priority |
||
79 | * |
||
80 | * @return void |
||
81 | */ |
||
82 | abstract public static function created($callback, $priority = 0); |
||
83 | |||
84 | /** |
||
85 | * Register a deleted model event with the dispatcher. |
||
86 | * |
||
87 | * @param \Closure|string $callback |
||
88 | * @param int $priority |
||
89 | * |
||
90 | * @return void |
||
91 | */ |
||
92 | abstract public static function deleted($callback, $priority = 0); |
||
93 | |||
94 | /** |
||
95 | * Forget model cache on create/update/delete. |
||
96 | * |
||
97 | * @return void |
||
98 | */ |
||
99 | public static function bootCacheableEloquent() |
||
119 | |||
120 | /** |
||
121 | * Set the IoC container instance. |
||
122 | * |
||
123 | * @param \Illuminate\Contracts\Container\Container $container |
||
124 | * |
||
125 | * @return void |
||
126 | */ |
||
127 | public static function setContainer(Container $container) |
||
131 | |||
132 | /** |
||
133 | * Get the IoC container instance or any of its services. |
||
134 | * |
||
135 | * @param string|null $service |
||
136 | * |
||
137 | * @return mixed |
||
138 | */ |
||
139 | public static function getContainer($service = null) |
||
143 | |||
144 | /** |
||
145 | * Store the given cache key for the given model by mimicking cache tags. |
||
146 | * |
||
147 | * @param string $modelName |
||
148 | * @param string $cacheKey |
||
149 | * |
||
150 | * @return void |
||
151 | */ |
||
152 | protected static function storeCacheKey(string $modelName, string $cacheKey) |
||
162 | |||
163 | /** |
||
164 | * Get cache keys from the given file. |
||
165 | * |
||
166 | * @param string $file |
||
167 | * |
||
168 | * @return array |
||
169 | */ |
||
170 | protected static function getCacheKeys($file) |
||
178 | |||
179 | /** |
||
180 | * Flush cache keys of the given model by mimicking cache tags. |
||
181 | * |
||
182 | * @param string $modelName |
||
183 | * |
||
184 | * @return array |
||
185 | */ |
||
186 | protected static function flushCacheKeys(string $modelName): array |
||
202 | |||
203 | /** |
||
204 | * Set the model cache lifetime. |
||
205 | * |
||
206 | * @param float|int $cacheLifetime |
||
207 | * |
||
208 | * @return $this |
||
209 | */ |
||
210 | public function setCacheLifetime($cacheLifetime) |
||
216 | |||
217 | /** |
||
218 | * Get the model cache lifetime. |
||
219 | * |
||
220 | * @return float|int |
||
221 | */ |
||
222 | public function getCacheLifetime() |
||
226 | |||
227 | /** |
||
228 | * Set the model cache driver. |
||
229 | * |
||
230 | * @param string $cacheDriver |
||
231 | * |
||
232 | * @return $this |
||
233 | */ |
||
234 | public function setCacheDriver($cacheDriver) |
||
240 | |||
241 | /** |
||
242 | * Get the model cache driver. |
||
243 | * |
||
244 | * @return string |
||
245 | */ |
||
246 | public function getCacheDriver() |
||
250 | |||
251 | /** |
||
252 | * Determine if model cache clear is enabled. |
||
253 | * |
||
254 | * @return bool |
||
255 | */ |
||
256 | public static function isCacheClearEnabled() |
||
260 | |||
261 | /** |
||
262 | * Forget the model cache. |
||
263 | * |
||
264 | * @return void |
||
265 | */ |
||
266 | public static function forgetCache() |
||
282 | |||
283 | /** |
||
284 | * Fire the given event for the model. |
||
285 | * |
||
286 | * @param string $event |
||
287 | * @param bool $halt |
||
288 | * |
||
289 | * @return mixed |
||
290 | */ |
||
291 | protected static function fireCacheFlushEvent($event, $halt = true) |
||
306 | |||
307 | /** |
||
308 | * Reset cached model to its defaults. |
||
309 | * |
||
310 | * @return $this |
||
311 | */ |
||
312 | public function resetCacheConfig() |
||
319 | |||
320 | /** |
||
321 | * Generate unique cache key. |
||
322 | * |
||
323 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
324 | * @param array $columns |
||
325 | * |
||
326 | * @return string |
||
327 | */ |
||
328 | protected function generateCacheKey(Builder $builder, array $columns) |
||
361 | |||
362 | /** |
||
363 | * Cache given callback. |
||
364 | * |
||
365 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
366 | * @param array $columns |
||
367 | * @param \Closure $closure |
||
368 | * |
||
369 | * @return mixed |
||
370 | */ |
||
371 | public function cacheQuery(Builder $builder, array $columns, Closure $closure) |
||
399 | |||
400 | /** |
||
401 | * Create a new Eloquent query builder for the model. |
||
402 | * |
||
403 | * @param \Illuminate\Database\Query\Builder $query |
||
404 | * |
||
405 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
406 | */ |
||
407 | public function newEloquentBuilder($query) |
||
411 | } |
||
412 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.