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 | * Indicate if the model cache clear is enabled. |
||
34 | * |
||
35 | * @var bool |
||
36 | */ |
||
37 | protected static $cacheClearEnabled = true; |
||
38 | |||
39 | /** |
||
40 | * The model cache driver. |
||
41 | * |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $cacheDriver; |
||
45 | |||
46 | /** |
||
47 | * The model cache lifetime. |
||
48 | * |
||
49 | * @var float|int |
||
50 | */ |
||
51 | protected $cacheLifetime = -1; |
||
52 | |||
53 | /** |
||
54 | * Register an updated model event with the dispatcher. |
||
55 | * |
||
56 | * @param \Closure|string $callback |
||
57 | * |
||
58 | * @return void |
||
59 | */ |
||
60 | abstract public static function updated($callback); |
||
61 | |||
62 | /** |
||
63 | * Register a created model event with the dispatcher. |
||
64 | * |
||
65 | * @param \Closure|string $callback |
||
66 | * |
||
67 | * @return void |
||
68 | */ |
||
69 | abstract public static function created($callback); |
||
70 | |||
71 | /** |
||
72 | * Register a deleted model event with the dispatcher. |
||
73 | * |
||
74 | * @param \Closure|string $callback |
||
75 | * |
||
76 | * @return void |
||
77 | */ |
||
78 | abstract public static function deleted($callback); |
||
79 | |||
80 | /** |
||
81 | * Forget model cache on create/update/delete. |
||
82 | * |
||
83 | * @return void |
||
84 | */ |
||
85 | public static function bootCacheableEloquent() |
||
89 | |||
90 | /** |
||
91 | * Set the IoC container instance. |
||
92 | * |
||
93 | * @param \Illuminate\Contracts\Container\Container $container |
||
94 | * |
||
95 | * @return void |
||
96 | */ |
||
97 | public static function setContainer(Container $container) |
||
101 | |||
102 | /** |
||
103 | * Get the IoC container instance or any of its services. |
||
104 | * |
||
105 | * @param string|null $service |
||
106 | * |
||
107 | * @return mixed |
||
108 | */ |
||
109 | public static function getContainer($service = null) |
||
113 | |||
114 | /** |
||
115 | * Store the given cache key for the given model by mimicking cache tags. |
||
116 | * |
||
117 | * @param string $modelName |
||
118 | * @param string $cacheKey |
||
119 | * |
||
120 | * @return void |
||
121 | */ |
||
122 | protected static function storeCacheKey(string $modelName, string $cacheKey) |
||
132 | |||
133 | /** |
||
134 | * Get cache keys from the given file. |
||
135 | * |
||
136 | * @param string $file |
||
137 | * |
||
138 | * @return array |
||
139 | */ |
||
140 | protected static function getCacheKeys($file) |
||
148 | |||
149 | /** |
||
150 | * Flush cache keys of the given model by mimicking cache tags. |
||
151 | * |
||
152 | * @param string $modelName |
||
153 | * |
||
154 | * @return array |
||
155 | */ |
||
156 | protected static function flushCacheKeys(string $modelName): array |
||
172 | |||
173 | /** |
||
174 | * Set the model cache lifetime. |
||
175 | * |
||
176 | * @param float|int $cacheLifetime |
||
177 | * |
||
178 | * @return $this |
||
179 | */ |
||
180 | public function setCacheLifetime($cacheLifetime) |
||
186 | |||
187 | /** |
||
188 | * Get the model cache lifetime. |
||
189 | * |
||
190 | * @return float|int |
||
191 | */ |
||
192 | public function getCacheLifetime() |
||
196 | |||
197 | /** |
||
198 | * Set the model cache driver. |
||
199 | * |
||
200 | * @param string $cacheDriver |
||
201 | * |
||
202 | * @return $this |
||
203 | */ |
||
204 | public function setCacheDriver($cacheDriver) |
||
210 | |||
211 | /** |
||
212 | * Get the model cache driver. |
||
213 | * |
||
214 | * @return string |
||
215 | */ |
||
216 | public function getCacheDriver() |
||
220 | |||
221 | /** |
||
222 | * Determine if model cache clear is enabled. |
||
223 | * |
||
224 | * @return bool |
||
225 | */ |
||
226 | public static function isCacheClearEnabled() |
||
230 | |||
231 | /** |
||
232 | * Forget the model cache. |
||
233 | * |
||
234 | * @return void |
||
235 | */ |
||
236 | public static function forgetCache() |
||
252 | |||
253 | /** |
||
254 | * Fire the given event for the model. |
||
255 | * |
||
256 | * @param string $event |
||
257 | * @param bool $halt |
||
258 | * |
||
259 | * @return mixed |
||
260 | */ |
||
261 | protected static function fireCacheFlushEvent($event, $halt = true) |
||
276 | |||
277 | /** |
||
278 | * Reset cached model to its defaults. |
||
279 | * |
||
280 | * @return $this |
||
281 | */ |
||
282 | public function resetCacheConfig() |
||
289 | |||
290 | /** |
||
291 | * Generate unique cache key. |
||
292 | * |
||
293 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
294 | * @param array $columns |
||
295 | * |
||
296 | * @return string |
||
297 | */ |
||
298 | protected function generateCacheKey(Builder $builder, array $columns) |
||
331 | |||
332 | /** |
||
333 | * Cache given callback. |
||
334 | * |
||
335 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
336 | * @param array $columns |
||
337 | * @param \Closure $closure |
||
338 | * |
||
339 | * @return mixed |
||
340 | */ |
||
341 | public function cacheQuery(Builder $builder, array $columns, Closure $closure) |
||
369 | |||
370 | /** |
||
371 | * Create a new Eloquent query builder for the model. |
||
372 | * |
||
373 | * @param \Illuminate\Database\Query\Builder $query |
||
374 | * |
||
375 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
376 | */ |
||
377 | public function newEloquentBuilder($query) |
||
381 | |||
382 | /** |
||
383 | * Attach events to the model. |
||
384 | * |
||
385 | * @return void |
||
386 | */ |
||
387 | protected static function attacheEvents() |
||
407 | } |
||
408 |
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.