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 |
||
65 | |||
66 | /** |
||
67 | * Store the given cache key for the given model by mimicking cache tags. |
||
68 | * |
||
69 | * @param string $modelName |
||
70 | * @param string $cacheKey |
||
71 | * |
||
72 | * @return void |
||
73 | */ |
||
74 | protected static function storeCacheKey(string $modelName, string $cacheKey): void |
||
84 | |||
85 | /** |
||
86 | * Get cache keys from the given file. |
||
87 | * |
||
88 | * @param string $file |
||
89 | * |
||
90 | * @return array |
||
91 | */ |
||
92 | protected static function getCacheKeys($file): array |
||
102 | |||
103 | /** |
||
104 | * Flush cache keys of the given model by mimicking cache tags. |
||
105 | * |
||
106 | * @param string $modelName |
||
107 | * |
||
108 | * @return array |
||
109 | */ |
||
110 | protected static function flushCacheKeys(string $modelName): array |
||
126 | |||
127 | /** |
||
128 | * Set the model cache lifetime. |
||
129 | * |
||
130 | * @param int $cacheLifetime |
||
131 | * |
||
132 | * @return $this |
||
133 | */ |
||
134 | public function setCacheLifetime(int $cacheLifetime) |
||
140 | |||
141 | /** |
||
142 | * Get the model cache lifetime. |
||
143 | * |
||
144 | * @return int |
||
145 | */ |
||
146 | public function getCacheLifetime(): int |
||
150 | |||
151 | /** |
||
152 | * Set the model cache driver. |
||
153 | * |
||
154 | * @param string $cacheDriver |
||
155 | * |
||
156 | * @return $this |
||
157 | */ |
||
158 | public function setCacheDriver($cacheDriver) |
||
164 | |||
165 | /** |
||
166 | * Get the model cache driver. |
||
167 | * |
||
168 | * @return string|null |
||
169 | */ |
||
170 | public function getCacheDriver(): ?string |
||
174 | |||
175 | /** |
||
176 | * Determine if model cache clear is enabled. |
||
177 | * |
||
178 | * @return bool |
||
179 | */ |
||
180 | public function isCacheClearEnabled(): bool |
||
184 | |||
185 | /** |
||
186 | * Forget the model cache. |
||
187 | * |
||
188 | * @return void |
||
189 | */ |
||
190 | public static function forgetCache() |
||
206 | |||
207 | /** |
||
208 | * Fire the given event for the model. |
||
209 | * |
||
210 | * @param string $event |
||
211 | * @param bool $halt |
||
212 | * |
||
213 | * @return mixed |
||
214 | */ |
||
215 | protected static function fireCacheFlushEvent($event, $halt = true) |
||
230 | |||
231 | /** |
||
232 | * Reset cached model to its defaults. |
||
233 | * |
||
234 | * @return $this |
||
235 | */ |
||
236 | public function resetCacheConfig() |
||
243 | |||
244 | /** |
||
245 | * Generate unique cache key. |
||
246 | * |
||
247 | * @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $builder |
||
248 | * @param array $columns |
||
249 | * |
||
250 | * @return string |
||
251 | */ |
||
252 | protected function generateCacheKey($builder, array $columns): string |
||
289 | |||
290 | /** |
||
291 | * Cache given callback. |
||
292 | * |
||
293 | * @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $builder |
||
294 | * @param array $columns |
||
295 | * @param \Closure $closure |
||
296 | * |
||
297 | * @return mixed |
||
298 | */ |
||
299 | public function cacheQuery($builder, array $columns, Closure $closure) |
||
327 | |||
328 | /** |
||
329 | * Create a new Eloquent query builder for the model. |
||
330 | * |
||
331 | * @param \Illuminate\Database\Query\Builder $query |
||
332 | * |
||
333 | * @return \Illuminate\Database\Eloquent\Builder|static |
||
334 | */ |
||
335 | public function newEloquentBuilder($query) |
||
339 | } |
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: