1 | <?php |
||
11 | trait CacheableEloquent |
||
12 | { |
||
13 | /** |
||
14 | * Register an updated model event with the dispatcher. |
||
15 | * |
||
16 | * @param \Closure|string $callback |
||
17 | * |
||
18 | * @return void |
||
19 | */ |
||
20 | abstract public static function updated($callback); |
||
21 | |||
22 | /** |
||
23 | * Register a created model event with the dispatcher. |
||
24 | * |
||
25 | * @param \Closure|string $callback |
||
26 | * |
||
27 | * @return void |
||
28 | */ |
||
29 | abstract public static function created($callback); |
||
30 | |||
31 | /** |
||
32 | * Register a deleted model event with the dispatcher. |
||
33 | * |
||
34 | * @param \Closure|string $callback |
||
35 | * |
||
36 | * @return void |
||
37 | */ |
||
38 | abstract public static function deleted($callback); |
||
39 | |||
40 | /** |
||
41 | * Boot the cacheable eloquent trait for a model. |
||
42 | * |
||
43 | * @return void |
||
44 | */ |
||
45 | public static function bootCacheableEloquent(): void |
||
59 | |||
60 | /** |
||
61 | * Store the given cache key for the given model by mimicking cache tags. |
||
62 | * |
||
63 | * @param string $modelName |
||
64 | * @param string $cacheKey |
||
65 | * |
||
66 | * @return void |
||
67 | */ |
||
68 | protected static function storeCacheKey(string $modelName, string $cacheKey): void |
||
78 | |||
79 | /** |
||
80 | * Get cache keys from the given file. |
||
81 | * |
||
82 | * @param string $file |
||
83 | * |
||
84 | * @return array |
||
85 | */ |
||
86 | protected static function getCacheKeys($file): array |
||
96 | |||
97 | /** |
||
98 | * Flush cache keys of the given model by mimicking cache tags. |
||
99 | * |
||
100 | * @param string $modelName |
||
101 | * |
||
102 | * @return array |
||
103 | */ |
||
104 | protected static function flushCacheKeys(string $modelName): array |
||
120 | |||
121 | /** |
||
122 | * Set the model cache lifetime. |
||
123 | * |
||
124 | * @param int $cacheLifetime |
||
125 | * |
||
126 | * @return $this |
||
127 | */ |
||
128 | public function setCacheLifetime(int $cacheLifetime) |
||
134 | |||
135 | /** |
||
136 | * Get the model cache lifetime. |
||
137 | * |
||
138 | * @return int |
||
139 | */ |
||
140 | public function getCacheLifetime(): int |
||
144 | |||
145 | /** |
||
146 | * Set the model cache driver. |
||
147 | * |
||
148 | * @param string $cacheDriver |
||
149 | * |
||
150 | * @return $this |
||
151 | */ |
||
152 | public function setCacheDriver($cacheDriver) |
||
158 | |||
159 | /** |
||
160 | * Get the model cache driver. |
||
161 | * |
||
162 | * @return string|null |
||
163 | */ |
||
164 | public function getCacheDriver(): ?string |
||
168 | |||
169 | /** |
||
170 | * Determine if model cache clear is enabled. |
||
171 | * |
||
172 | * @return bool |
||
173 | */ |
||
174 | public function isCacheClearEnabled(): bool |
||
178 | |||
179 | /** |
||
180 | * Forget the model cache. |
||
181 | * |
||
182 | * @return void |
||
183 | */ |
||
184 | public static function forgetCache() |
||
200 | |||
201 | /** |
||
202 | * Fire the given event for the model. |
||
203 | * |
||
204 | * @param string $event |
||
205 | * @param bool $halt |
||
206 | * |
||
207 | * @return mixed |
||
208 | */ |
||
209 | protected static function fireCacheFlushEvent($event, $halt = true) |
||
224 | |||
225 | /** |
||
226 | * Reset cached model to its defaults. |
||
227 | * |
||
228 | * @return $this |
||
229 | */ |
||
230 | public function resetCacheConfig() |
||
237 | |||
238 | /** |
||
239 | * Generate unique cache key. |
||
240 | * |
||
241 | * @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $builder |
||
242 | * @param array $columns |
||
243 | * |
||
244 | * @return string |
||
245 | */ |
||
246 | protected function generateCacheKey($builder, array $columns): string |
||
279 | |||
280 | /** |
||
281 | * Cache given callback. |
||
282 | * |
||
283 | * @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $builder |
||
284 | * @param array $columns |
||
285 | * @param \Closure $closure |
||
286 | * |
||
287 | * @return mixed |
||
288 | */ |
||
289 | public function cacheQuery($builder, array $columns, Closure $closure) |
||
317 | |||
318 | /** |
||
319 | * Create a new Eloquent query builder for the model. |
||
320 | * |
||
321 | * @param \Illuminate\Database\Query\Builder $query |
||
322 | * |
||
323 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
324 | */ |
||
325 | public function newEloquentBuilder($query) |
||
329 | } |
||
330 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: