1 | <?php |
||
24 | trait CacheableEloquent |
||
25 | { |
||
26 | /** |
||
27 | * Indicate if the model cache clear is enabled. |
||
28 | * |
||
29 | * @var bool |
||
30 | */ |
||
31 | protected static $cacheClearEnabled = true; |
||
32 | |||
33 | /** |
||
34 | * The model cache driver. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $cacheDriver; |
||
39 | |||
40 | /** |
||
41 | * The model cache lifetime. |
||
42 | * |
||
43 | * @var float|int |
||
44 | */ |
||
45 | protected $cacheLifetime = -1; |
||
46 | |||
47 | /** |
||
48 | * Register an updated model event with the dispatcher. |
||
49 | * |
||
50 | * @param \Closure|string $callback |
||
51 | * |
||
52 | * @return void |
||
53 | */ |
||
54 | abstract public static function updated($callback); |
||
55 | |||
56 | /** |
||
57 | * Register a created model event with the dispatcher. |
||
58 | * |
||
59 | * @param \Closure|string $callback |
||
60 | * |
||
61 | * @return void |
||
62 | */ |
||
63 | abstract public static function created($callback); |
||
64 | |||
65 | /** |
||
66 | * Register a deleted model event with the dispatcher. |
||
67 | * |
||
68 | * @param \Closure|string $callback |
||
69 | * |
||
70 | * @return void |
||
71 | */ |
||
72 | abstract public static function deleted($callback); |
||
73 | |||
74 | /** |
||
75 | * Forget model cache on create/update/delete. |
||
76 | * |
||
77 | * @return void |
||
78 | */ |
||
79 | public static function bootCacheableEloquent() |
||
83 | |||
84 | /** |
||
85 | * Store the given cache key for the given model by mimicking cache tags. |
||
86 | * |
||
87 | * @param string $modelName |
||
88 | * @param string $cacheKey |
||
89 | * |
||
90 | * @return void |
||
91 | */ |
||
92 | protected static function storeCacheKey(string $modelName, string $cacheKey) |
||
102 | |||
103 | /** |
||
104 | * Get cache keys from the given file. |
||
105 | * |
||
106 | * @param string $file |
||
107 | * |
||
108 | * @return array |
||
109 | */ |
||
110 | protected static function getCacheKeys($file) |
||
118 | |||
119 | /** |
||
120 | * Flush cache keys of the given model by mimicking cache tags. |
||
121 | * |
||
122 | * @param string $modelName |
||
123 | * |
||
124 | * @return array |
||
125 | */ |
||
126 | protected static function flushCacheKeys(string $modelName): array |
||
142 | |||
143 | /** |
||
144 | * Set the model cache lifetime. |
||
145 | * |
||
146 | * @param float|int $cacheLifetime |
||
147 | * |
||
148 | * @return $this |
||
149 | */ |
||
150 | public function setCacheLifetime($cacheLifetime) |
||
156 | |||
157 | /** |
||
158 | * Get the model cache lifetime. |
||
159 | * |
||
160 | * @return float|int |
||
161 | */ |
||
162 | public function getCacheLifetime() |
||
166 | |||
167 | /** |
||
168 | * Set the model cache driver. |
||
169 | * |
||
170 | * @param string $cacheDriver |
||
171 | * |
||
172 | * @return $this |
||
173 | */ |
||
174 | public function setCacheDriver($cacheDriver) |
||
180 | |||
181 | /** |
||
182 | * Get the model cache driver. |
||
183 | * |
||
184 | * @return string |
||
185 | */ |
||
186 | public function getCacheDriver() |
||
190 | |||
191 | /** |
||
192 | * Determine if model cache clear is enabled. |
||
193 | * |
||
194 | * @return bool |
||
195 | */ |
||
196 | public static function isCacheClearEnabled() |
||
200 | |||
201 | /** |
||
202 | * Forget the model cache. |
||
203 | * |
||
204 | * @return void |
||
205 | */ |
||
206 | public static function forgetCache() |
||
222 | |||
223 | /** |
||
224 | * Fire the given event for the model. |
||
225 | * |
||
226 | * @param string $event |
||
227 | * @param bool $halt |
||
228 | * |
||
229 | * @return mixed |
||
230 | */ |
||
231 | protected static function fireCacheFlushEvent($event, $halt = true) |
||
246 | |||
247 | /** |
||
248 | * Reset cached model to its defaults. |
||
249 | * |
||
250 | * @return $this |
||
251 | */ |
||
252 | public function resetCacheConfig() |
||
259 | |||
260 | /** |
||
261 | * Generate unique cache key. |
||
262 | * |
||
263 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
264 | * @param array $columns |
||
265 | * |
||
266 | * @return string |
||
267 | */ |
||
268 | protected function generateCacheKey(Builder $builder, array $columns) |
||
301 | |||
302 | /** |
||
303 | * Cache given callback. |
||
304 | * |
||
305 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
306 | * @param array $columns |
||
307 | * @param \Closure $closure |
||
308 | * |
||
309 | * @return mixed |
||
310 | */ |
||
311 | public function cacheQuery(Builder $builder, array $columns, Closure $closure) |
||
339 | |||
340 | /** |
||
341 | * Create a new Eloquent query builder for the model. |
||
342 | * |
||
343 | * @param \Illuminate\Database\Query\Builder $query |
||
344 | * |
||
345 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
346 | */ |
||
347 | public function newEloquentBuilder($query) |
||
351 | |||
352 | /** |
||
353 | * Attach events to the model. |
||
354 | * |
||
355 | * @return void |
||
356 | */ |
||
357 | protected static function attacheEvents() |
||
377 | } |
||
378 |
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.