@@ -13,111 +13,111 @@ discard block |
||
13 | 13 | class ArrayCacheStore implements CacheerInterface |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @param array $arrayStore |
|
18 | - */ |
|
19 | - private array $arrayStore = []; |
|
20 | - |
|
21 | - /** |
|
22 | - * @var boolean |
|
23 | - */ |
|
24 | - private bool $success = false; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - private string $message = ''; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var ?CacheLogger |
|
33 | - */ |
|
34 | - private ?CacheLogger $logger = null; |
|
35 | - |
|
36 | - /** |
|
37 | - * ArrayCacheStore constructor. |
|
38 | - * |
|
39 | - * @param string $logPath |
|
40 | - */ |
|
41 | - public function __construct(string $logPath) |
|
42 | - { |
|
16 | + /** |
|
17 | + * @param array $arrayStore |
|
18 | + */ |
|
19 | + private array $arrayStore = []; |
|
20 | + |
|
21 | + /** |
|
22 | + * @var boolean |
|
23 | + */ |
|
24 | + private bool $success = false; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + private string $message = ''; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var ?CacheLogger |
|
33 | + */ |
|
34 | + private ?CacheLogger $logger = null; |
|
35 | + |
|
36 | + /** |
|
37 | + * ArrayCacheStore constructor. |
|
38 | + * |
|
39 | + * @param string $logPath |
|
40 | + */ |
|
41 | + public function __construct(string $logPath) |
|
42 | + { |
|
43 | 43 | $this->logger = new CacheLogger($logPath); |
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * Appends data to an existing cache item. |
|
48 | - * |
|
49 | - * @param string $cacheKey |
|
50 | - * @param mixed $cacheData |
|
51 | - * @param string $namespace |
|
52 | - * @return bool |
|
53 | - */ |
|
54 | - public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = ''): bool |
|
55 | - { |
|
56 | - $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
|
57 | - |
|
58 | - if (!$this->has($cacheKey, $namespace)) { |
|
59 | - $this->setMessage("cacheData can't be appended, because doesn't exist or expired", false); |
|
60 | - $this->logger->debug("{$this->getMessage()} from array driver."); |
|
61 | - return false; |
|
62 | - } |
|
63 | - |
|
64 | - $this->arrayStore[$arrayStoreKey]['cacheData'] = serialize($cacheData); |
|
65 | - $this->setMessage("Cache appended successfully", true); |
|
66 | - return true; |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * Builds a unique key for the array store. |
|
71 | - * |
|
72 | - * @param string $cacheKey |
|
73 | - * @param string $namespace |
|
74 | - * @return string |
|
75 | - */ |
|
76 | - private function buildArrayKey(string $cacheKey, string $namespace = ''): string |
|
77 | - { |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * Appends data to an existing cache item. |
|
48 | + * |
|
49 | + * @param string $cacheKey |
|
50 | + * @param mixed $cacheData |
|
51 | + * @param string $namespace |
|
52 | + * @return bool |
|
53 | + */ |
|
54 | + public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = ''): bool |
|
55 | + { |
|
56 | + $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
|
57 | + |
|
58 | + if (!$this->has($cacheKey, $namespace)) { |
|
59 | + $this->setMessage("cacheData can't be appended, because doesn't exist or expired", false); |
|
60 | + $this->logger->debug("{$this->getMessage()} from array driver."); |
|
61 | + return false; |
|
62 | + } |
|
63 | + |
|
64 | + $this->arrayStore[$arrayStoreKey]['cacheData'] = serialize($cacheData); |
|
65 | + $this->setMessage("Cache appended successfully", true); |
|
66 | + return true; |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * Builds a unique key for the array store. |
|
71 | + * |
|
72 | + * @param string $cacheKey |
|
73 | + * @param string $namespace |
|
74 | + * @return string |
|
75 | + */ |
|
76 | + private function buildArrayKey(string $cacheKey, string $namespace = ''): string |
|
77 | + { |
|
78 | 78 | return !empty($namespace) ? ($namespace . ':' . $cacheKey) : $cacheKey; |
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Clears a specific cache item. |
|
83 | - * |
|
84 | - * @param string $cacheKey |
|
85 | - * @param string $namespace |
|
86 | - * @return void |
|
87 | - */ |
|
88 | - public function clearCache(string $cacheKey, string $namespace = ''): void |
|
89 | - { |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Clears a specific cache item. |
|
83 | + * |
|
84 | + * @param string $cacheKey |
|
85 | + * @param string $namespace |
|
86 | + * @return void |
|
87 | + */ |
|
88 | + public function clearCache(string $cacheKey, string $namespace = ''): void |
|
89 | + { |
|
90 | 90 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
91 | 91 | unset($this->arrayStore[$arrayStoreKey]); |
92 | 92 | $this->setMessage("Cache cleared successfully", true); |
93 | 93 | $this->logger->debug("{$this->getMessage()} from array driver."); |
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Decrements a cache item by a specified amount. |
|
98 | - * |
|
99 | - * @param string $cacheKey |
|
100 | - * @param int $amount |
|
101 | - * @param string $namespace |
|
102 | - * @return bool |
|
103 | - */ |
|
104 | - public function decrement(string $cacheKey, int $amount = 1, string $namespace = ''): bool |
|
105 | - { |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Decrements a cache item by a specified amount. |
|
98 | + * |
|
99 | + * @param string $cacheKey |
|
100 | + * @param int $amount |
|
101 | + * @param string $namespace |
|
102 | + * @return bool |
|
103 | + */ |
|
104 | + public function decrement(string $cacheKey, int $amount = 1, string $namespace = ''): bool |
|
105 | + { |
|
106 | 106 | return $this->increment($cacheKey, ($amount * -1), $namespace); |
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Flushes all cache items. |
|
111 | - * |
|
112 | - * @return void |
|
113 | - */ |
|
114 | - public function flushCache(): void |
|
115 | - { |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Flushes all cache items. |
|
111 | + * |
|
112 | + * @return void |
|
113 | + */ |
|
114 | + public function flushCache(): void |
|
115 | + { |
|
116 | 116 | unset($this->arrayStore); |
117 | 117 | $this->arrayStore = []; |
118 | 118 | $this->setMessage("Cache flushed successfully", true); |
119 | 119 | $this->logger->debug("{$this->getMessage()} from array driver."); |
120 | - } |
|
120 | + } |
|
121 | 121 | |
122 | 122 | /** |
123 | 123 | * Stores a cache item permanently. |
@@ -126,234 +126,234 @@ discard block |
||
126 | 126 | * @param mixed $cacheData |
127 | 127 | * @return void |
128 | 128 | */ |
129 | - public function forever(string $cacheKey, mixed $cacheData): void |
|
130 | - { |
|
129 | + public function forever(string $cacheKey, mixed $cacheData): void |
|
130 | + { |
|
131 | 131 | $this->putCache($cacheKey, $cacheData, ttl: 31536000 * 1000); |
132 | 132 | $this->setMessage($this->getMessage(), $this->isSuccess()); |
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Retrieves a single cache item. |
|
137 | - * |
|
138 | - * @param string $cacheKey |
|
139 | - * @param string $namespace |
|
140 | - * @param int|string $ttl |
|
141 | - * @return mixed |
|
142 | - */ |
|
143 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed |
|
144 | - { |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Retrieves a single cache item. |
|
137 | + * |
|
138 | + * @param string $cacheKey |
|
139 | + * @param string $namespace |
|
140 | + * @param int|string $ttl |
|
141 | + * @return mixed |
|
142 | + */ |
|
143 | + public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed |
|
144 | + { |
|
145 | 145 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
146 | 146 | |
147 | 147 | if (!$this->has($cacheKey, $namespace)) { |
148 | - $this->handleCacheNotFound(); |
|
149 | - return false; |
|
148 | + $this->handleCacheNotFound(); |
|
149 | + return false; |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | $cacheData = $this->arrayStore[$arrayStoreKey]; |
153 | 153 | if ($this->isExpired($cacheData)) { |
154 | - $this->handleCacheExpired($arrayStoreKey); |
|
155 | - return false; |
|
154 | + $this->handleCacheExpired($arrayStoreKey); |
|
155 | + return false; |
|
156 | 156 | } |
157 | 157 | |
158 | 158 | $this->setMessage("Cache retrieved successfully", true); |
159 | 159 | $this->logger->debug("{$this->getMessage()} from array driver."); |
160 | 160 | return $this->serialize($cacheData['cacheData'], false); |
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Verify if the cache is expired. |
|
165 | - * |
|
166 | - * @param array $cacheData |
|
167 | - * @return bool |
|
168 | - */ |
|
169 | - private function isExpired(array $cacheData): bool |
|
170 | - { |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Verify if the cache is expired. |
|
165 | + * |
|
166 | + * @param array $cacheData |
|
167 | + * @return bool |
|
168 | + */ |
|
169 | + private function isExpired(array $cacheData): bool |
|
170 | + { |
|
171 | 171 | $expirationTime = $cacheData['expirationTime'] ?? 0; |
172 | 172 | $now = time(); |
173 | 173 | return $expirationTime !== 0 && $now >= $expirationTime; |
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Handles the case when cache data is not found. |
|
178 | - * |
|
179 | - * @return void |
|
180 | - */ |
|
181 | - private function handleCacheNotFound(): void |
|
182 | - { |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Handles the case when cache data is not found. |
|
178 | + * |
|
179 | + * @return void |
|
180 | + */ |
|
181 | + private function handleCacheNotFound(): void |
|
182 | + { |
|
183 | 183 | $this->setMessage("cacheData not found, does not exists or expired", false); |
184 | 184 | $this->logger->debug("{$this->getMessage()} from array driver."); |
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Handles the case when cache data has expired. |
|
189 | - * |
|
190 | - * @param string $arrayStoreKey |
|
191 | - * @return void |
|
192 | - */ |
|
193 | - private function handleCacheExpired(string $arrayStoreKey): void |
|
194 | - { |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Handles the case when cache data has expired. |
|
189 | + * |
|
190 | + * @param string $arrayStoreKey |
|
191 | + * @return void |
|
192 | + */ |
|
193 | + private function handleCacheExpired(string $arrayStoreKey): void |
|
194 | + { |
|
195 | 195 | $parts = explode(':', $arrayStoreKey, 2); |
196 | 196 | if (count($parts) === 2) { |
197 | - list($np, $key) = $parts; |
|
197 | + list($np, $key) = $parts; |
|
198 | 198 | } else { |
199 | - $np = ''; |
|
200 | - $key = $arrayStoreKey; |
|
199 | + $np = ''; |
|
200 | + $key = $arrayStoreKey; |
|
201 | 201 | } |
202 | 202 | $this->clearCache($key, $np); |
203 | 203 | $this->setMessage("cacheKey: {$key} has expired.", false); |
204 | 204 | $this->logger->debug("{$this->getMessage()} from array driver."); |
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Gets all items in a specific namespace. |
|
209 | - * |
|
210 | - * @param string $namespace |
|
211 | - * @return array |
|
212 | - */ |
|
213 | - public function getAll(string $namespace = ''): array |
|
214 | - { |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Gets all items in a specific namespace. |
|
209 | + * |
|
210 | + * @param string $namespace |
|
211 | + * @return array |
|
212 | + */ |
|
213 | + public function getAll(string $namespace = ''): array |
|
214 | + { |
|
215 | 215 | $results = []; |
216 | 216 | foreach ($this->arrayStore as $key => $data) { |
217 | - if (str_starts_with($key, $namespace . ':') || empty($namespace)) { |
|
217 | + if (str_starts_with($key, $namespace . ':') || empty($namespace)) { |
|
218 | 218 | $results[$key] = $this->serialize($data['cacheData'], false); |
219 | - } |
|
219 | + } |
|
220 | 220 | } |
221 | 221 | return $results; |
222 | - } |
|
223 | - |
|
224 | - /** |
|
225 | - * Retrieves multiple cache items by their keys. |
|
226 | - * |
|
227 | - * @param array $cacheKeys |
|
228 | - * @param string $namespace |
|
229 | - * @param string|int $ttl |
|
230 | - * @return array |
|
231 | - */ |
|
232 | - public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): array |
|
233 | - { |
|
222 | + } |
|
223 | + |
|
224 | + /** |
|
225 | + * Retrieves multiple cache items by their keys. |
|
226 | + * |
|
227 | + * @param array $cacheKeys |
|
228 | + * @param string $namespace |
|
229 | + * @param string|int $ttl |
|
230 | + * @return array |
|
231 | + */ |
|
232 | + public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): array |
|
233 | + { |
|
234 | 234 | $results = []; |
235 | 235 | foreach ($cacheKeys as $cacheKey) { |
236 | - $results[$cacheKey] = $this->getCache($cacheKey, $namespace, $ttl); |
|
236 | + $results[$cacheKey] = $this->getCache($cacheKey, $namespace, $ttl); |
|
237 | 237 | } |
238 | 238 | return $results; |
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Checks if a cache item exists. |
|
243 | - * |
|
244 | - * @param string $cacheKey |
|
245 | - * @param string $namespace |
|
246 | - * @return bool |
|
247 | - */ |
|
248 | - public function has(string $cacheKey, string $namespace = ''): bool |
|
249 | - { |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Checks if a cache item exists. |
|
243 | + * |
|
244 | + * @param string $cacheKey |
|
245 | + * @param string $namespace |
|
246 | + * @return bool |
|
247 | + */ |
|
248 | + public function has(string $cacheKey, string $namespace = ''): bool |
|
249 | + { |
|
250 | 250 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
251 | 251 | $exists = isset($this->arrayStore[$arrayStoreKey]) && time() < $this->arrayStore[$arrayStoreKey]['expirationTime']; |
252 | 252 | |
253 | 253 | $this->setMessage( |
254 | - $exists ? "Cache key: {$cacheKey} exists and it's available!" : "Cache key: {$cacheKey} does not exist or it's expired!", |
|
255 | - $exists |
|
254 | + $exists ? "Cache key: {$cacheKey} exists and it's available!" : "Cache key: {$cacheKey} does not exist or it's expired!", |
|
255 | + $exists |
|
256 | 256 | ); |
257 | 257 | $this->logger->debug("{$this->getMessage()} from array driver."); |
258 | 258 | |
259 | 259 | return $exists; |
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Increments a cache item by a specified amount. |
|
264 | - * |
|
265 | - * @param string $cacheKey |
|
266 | - * @param int $amount |
|
267 | - * @param string $namespace |
|
268 | - * @return bool |
|
269 | - */ |
|
270 | - public function increment(string $cacheKey, int $amount = 1, string $namespace = ''): bool |
|
271 | - { |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Increments a cache item by a specified amount. |
|
264 | + * |
|
265 | + * @param string $cacheKey |
|
266 | + * @param int $amount |
|
267 | + * @param string $namespace |
|
268 | + * @return bool |
|
269 | + */ |
|
270 | + public function increment(string $cacheKey, int $amount = 1, string $namespace = ''): bool |
|
271 | + { |
|
272 | 272 | $cacheData = $this->getCache($cacheKey, $namespace); |
273 | 273 | |
274 | 274 | if(!empty($cacheData) && is_numeric($cacheData)) { |
275 | - $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace); |
|
276 | - $this->setMessage($this->getMessage(), $this->isSuccess()); |
|
277 | - return true; |
|
275 | + $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace); |
|
276 | + $this->setMessage($this->getMessage(), $this->isSuccess()); |
|
277 | + return true; |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | return false; |
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * Checks if the operation was successful. |
|
285 | - * |
|
286 | - * @return boolean |
|
287 | - */ |
|
288 | - public function isSuccess(): bool |
|
289 | - { |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * Checks if the operation was successful. |
|
285 | + * |
|
286 | + * @return boolean |
|
287 | + */ |
|
288 | + public function isSuccess(): bool |
|
289 | + { |
|
290 | 290 | return $this->success; |
291 | - } |
|
292 | - |
|
293 | - /** |
|
294 | - * Gets the last message. |
|
295 | - * |
|
296 | - * @return string |
|
297 | - */ |
|
298 | - public function getMessage(): string |
|
299 | - { |
|
291 | + } |
|
292 | + |
|
293 | + /** |
|
294 | + * Gets the last message. |
|
295 | + * |
|
296 | + * @return string |
|
297 | + */ |
|
298 | + public function getMessage(): string |
|
299 | + { |
|
300 | 300 | return $this->message; |
301 | - } |
|
302 | - |
|
303 | - /** |
|
304 | - * Stores an item in the cache with a specific TTL. |
|
305 | - * |
|
306 | - * @param string $cacheKey |
|
307 | - * @param mixed $cacheData |
|
308 | - * @param string $namespace |
|
309 | - * @param int|string $ttl |
|
310 | - * @return bool |
|
311 | - */ |
|
312 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool |
|
313 | - { |
|
301 | + } |
|
302 | + |
|
303 | + /** |
|
304 | + * Stores an item in the cache with a specific TTL. |
|
305 | + * |
|
306 | + * @param string $cacheKey |
|
307 | + * @param mixed $cacheData |
|
308 | + * @param string $namespace |
|
309 | + * @param int|string $ttl |
|
310 | + * @return bool |
|
311 | + */ |
|
312 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool |
|
313 | + { |
|
314 | 314 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
315 | 315 | |
316 | 316 | $this->arrayStore[$arrayStoreKey] = [ |
317 | - 'cacheData' => serialize($cacheData), |
|
318 | - 'expirationTime' => time() + $ttl |
|
317 | + 'cacheData' => serialize($cacheData), |
|
318 | + 'expirationTime' => time() + $ttl |
|
319 | 319 | ]; |
320 | 320 | |
321 | 321 | $this->setMessage("Cache stored successfully", true); |
322 | 322 | $this->logger->debug("{$this->getMessage()} from Array driver."); |
323 | 323 | return true; |
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Stores multiple items in the cache in batches. |
|
328 | - * |
|
329 | - * @param array $items |
|
330 | - * @param string $namespace |
|
331 | - * @param int $batchSize |
|
332 | - * @return void |
|
333 | - */ |
|
334 | - public function putMany(array $items, string $namespace = '', int $batchSize = 100): void |
|
335 | - { |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Stores multiple items in the cache in batches. |
|
328 | + * |
|
329 | + * @param array $items |
|
330 | + * @param string $namespace |
|
331 | + * @param int $batchSize |
|
332 | + * @return void |
|
333 | + */ |
|
334 | + public function putMany(array $items, string $namespace = '', int $batchSize = 100): void |
|
335 | + { |
|
336 | 336 | $chunks = array_chunk($items, $batchSize, true); |
337 | 337 | |
338 | 338 | foreach ($chunks as $chunk) { |
339 | - foreach ($chunk as $key => $data) { |
|
340 | - $this->putCache($data['cacheKey'], $data['cacheData'], $namespace); |
|
339 | + foreach ($chunk as $key => $data) { |
|
340 | + $this->putCache($data['cacheKey'], $data['cacheData'], $namespace); |
|
341 | + } |
|
341 | 342 | } |
342 | - } |
|
343 | 343 | $this->setMessage("{$this->getMessage()}", $this->isSuccess()); |
344 | 344 | $this->logger->debug("{$this->getMessage()} from Array driver."); |
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Renews the expiration time of a cache item. |
|
349 | - * |
|
350 | - * @param string $cacheKey |
|
351 | - * @param string|int $ttl |
|
352 | - * @param string $namespace |
|
353 | - * @return void |
|
354 | - */ |
|
355 | - public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): void |
|
356 | - { |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Renews the expiration time of a cache item. |
|
349 | + * |
|
350 | + * @param string $cacheKey |
|
351 | + * @param string|int $ttl |
|
352 | + * @param string $namespace |
|
353 | + * @return void |
|
354 | + */ |
|
355 | + public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): void |
|
356 | + { |
|
357 | 357 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
358 | 358 | |
359 | 359 | if (isset($this->arrayStore[$arrayStoreKey])) { |
@@ -361,31 +361,31 @@ discard block |
||
361 | 361 | $this->arrayStore[$arrayStoreKey]['expirationTime'] = time() + $ttlSeconds; |
362 | 362 | $this->setMessage("cacheKey: {$cacheKey} renewed successfully", true); |
363 | 363 | $this->logger->debug("{$this->getMessage()} from array driver."); |
364 | - } |
|
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Sets a message and its success status. |
|
369 | - * |
|
370 | - * @param string $message |
|
371 | - * @param boolean $success |
|
372 | - * @return void |
|
373 | - */ |
|
374 | - private function setMessage(string $message, bool $success): void |
|
375 | - { |
|
364 | + } |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Sets a message and its success status. |
|
369 | + * |
|
370 | + * @param string $message |
|
371 | + * @param boolean $success |
|
372 | + * @return void |
|
373 | + */ |
|
374 | + private function setMessage(string $message, bool $success): void |
|
375 | + { |
|
376 | 376 | $this->message = $message; |
377 | 377 | $this->success = $success; |
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Serializes or unserializes data based on the flag. |
|
382 | - * |
|
383 | - * @param mixed $data |
|
384 | - * @param bool $serialize |
|
385 | - * @return mixed |
|
386 | - */ |
|
387 | - private function serialize(mixed $data, bool $serialize = true): mixed |
|
388 | - { |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * Serializes or unserializes data based on the flag. |
|
382 | + * |
|
383 | + * @param mixed $data |
|
384 | + * @param bool $serialize |
|
385 | + * @return mixed |
|
386 | + */ |
|
387 | + private function serialize(mixed $data, bool $serialize = true): mixed |
|
388 | + { |
|
389 | 389 | return $serialize ? serialize($data) : unserialize($data); |
390 | - } |
|
390 | + } |
|
391 | 391 | } |
@@ -13,29 +13,29 @@ discard block |
||
13 | 13 | class CacheMutator |
14 | 14 | { |
15 | 15 | /** |
16 | - * @var Cacheer |
|
17 | - */ |
|
16 | + * @var Cacheer |
|
17 | + */ |
|
18 | 18 | private Cacheer $cacheer; |
19 | 19 | |
20 | 20 | /** |
21 | - * CacheMutator constructor. |
|
22 | - * |
|
23 | - * @param Cacheer $cacheer |
|
24 | - */ |
|
21 | + * CacheMutator constructor. |
|
22 | + * |
|
23 | + * @param Cacheer $cacheer |
|
24 | + */ |
|
25 | 25 | public function __construct(Cacheer $cacheer) |
26 | 26 | { |
27 | 27 | $this->cacheer = $cacheer; |
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
31 | - * Adds a cache item if it does not already exist. |
|
32 | - * |
|
33 | - * @param string $cacheKey |
|
34 | - * @param mixed $cacheData |
|
35 | - * @param string $namespace |
|
36 | - * @param int|string $ttl |
|
37 | - * @return bool |
|
38 | - */ |
|
31 | + * Adds a cache item if it does not already exist. |
|
32 | + * |
|
33 | + * @param string $cacheKey |
|
34 | + * @param mixed $cacheData |
|
35 | + * @param string $namespace |
|
36 | + * @param int|string $ttl |
|
37 | + * @return bool |
|
38 | + */ |
|
39 | 39 | public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool |
40 | 40 | { |
41 | 41 | if (!empty($this->cacheer->getCache($cacheKey, $namespace))) { |
@@ -49,13 +49,13 @@ discard block |
||
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | - * Appends data to an existing cache item. |
|
53 | - * |
|
54 | - * @param string $cacheKey |
|
55 | - * @param mixed $cacheData |
|
56 | - * @param string $namespace |
|
57 | - * @return bool |
|
58 | - */ |
|
52 | + * Appends data to an existing cache item. |
|
53 | + * |
|
54 | + * @param string $cacheKey |
|
55 | + * @param mixed $cacheData |
|
56 | + * @param string $namespace |
|
57 | + * @return bool |
|
58 | + */ |
|
59 | 59 | public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = ''): bool |
60 | 60 | { |
61 | 61 | $this->cacheer->cacheStore->appendCache($cacheKey, $cacheData, $namespace); |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
68 | - * Clears a specific cache item. |
|
69 | - * |
|
70 | - * @param string $cacheKey |
|
71 | - * @param string $namespace |
|
72 | - * @return bool |
|
73 | - */ |
|
68 | + * Clears a specific cache item. |
|
69 | + * |
|
70 | + * @param string $cacheKey |
|
71 | + * @param string $namespace |
|
72 | + * @return bool |
|
73 | + */ |
|
74 | 74 | public function clearCache(string $cacheKey, string $namespace = ''): bool |
75 | 75 | { |
76 | 76 | $this->cacheer->cacheStore->clearCache($cacheKey, $namespace); |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | } |
81 | 81 | |
82 | 82 | /** |
83 | - * Decrements a numeric cache item by a specified amount. |
|
84 | - * |
|
85 | - * @param string $cacheKey |
|
86 | - * @param int $amount |
|
87 | - * @param string $namespace |
|
88 | - * @return bool |
|
89 | - */ |
|
83 | + * Decrements a numeric cache item by a specified amount. |
|
84 | + * |
|
85 | + * @param string $cacheKey |
|
86 | + * @param int $amount |
|
87 | + * @param string $namespace |
|
88 | + * @return bool |
|
89 | + */ |
|
90 | 90 | public function decrement(string $cacheKey, int $amount = 1, string $namespace = ''): bool |
91 | 91 | { |
92 | 92 | return $this->increment($cacheKey, ($amount * -1), $namespace); |
@@ -108,10 +108,10 @@ discard block |
||
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
111 | - * Flushes the entire cache. |
|
112 | - * |
|
113 | - * @return bool |
|
114 | - */ |
|
111 | + * Flushes the entire cache. |
|
112 | + * |
|
113 | + * @return bool |
|
114 | + */ |
|
115 | 115 | public function flushCache(): bool |
116 | 116 | { |
117 | 117 | $this->cacheer->cacheStore->flushCache(); |
@@ -160,13 +160,13 @@ discard block |
||
160 | 160 | } |
161 | 161 | |
162 | 162 | /** |
163 | - * Puts multiple cache items in a batch. |
|
164 | - * |
|
165 | - * @param array $items |
|
166 | - * @param string $namespace |
|
167 | - * @param int $batchSize |
|
168 | - * @return bool |
|
169 | - */ |
|
163 | + * Puts multiple cache items in a batch. |
|
164 | + * |
|
165 | + * @param array $items |
|
166 | + * @param string $namespace |
|
167 | + * @param int $batchSize |
|
168 | + * @return bool |
|
169 | + */ |
|
170 | 170 | public function putMany(array $items, string $namespace = '', int $batchSize = 100): bool |
171 | 171 | { |
172 | 172 | $this->cacheer->cacheStore->putMany($items, $namespace, $batchSize); |
@@ -176,13 +176,13 @@ discard block |
||
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
179 | - * Renews the cache item with a new TTL. |
|
180 | - * |
|
181 | - * @param string $cacheKey |
|
182 | - * @param int|string $ttl |
|
183 | - * @param string $namespace |
|
184 | - * @return bool |
|
185 | - */ |
|
179 | + * Renews the cache item with a new TTL. |
|
180 | + * |
|
181 | + * @param string $cacheKey |
|
182 | + * @param int|string $ttl |
|
183 | + * @param string $namespace |
|
184 | + * @return bool |
|
185 | + */ |
|
186 | 186 | public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): bool |
187 | 187 | { |
188 | 188 | $this->cacheer->cacheStore->renewCache($cacheKey, $ttl, $namespace); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param int|string $ttl |
37 | 37 | * @return bool |
38 | 38 | */ |
39 | - public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool |
|
39 | + public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600): bool |
|
40 | 40 | { |
41 | 41 | if (!empty($this->cacheer->getCache($cacheKey, $namespace))) { |
42 | 42 | return true; |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * @param int|string $ttl |
151 | 151 | * @return bool |
152 | 152 | */ |
153 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool |
|
153 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600): bool |
|
154 | 154 | { |
155 | 155 | $data = CacheerHelper::prepareForStorage($cacheData, $this->cacheer->isCompressionEnabled(), $this->cacheer->getEncryptionKey()); |
156 | 156 | $this->cacheer->cacheStore->putCache($cacheKey, $data, $namespace, $ttl); |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | * @param string $namespace |
184 | 184 | * @return bool |
185 | 185 | */ |
186 | - public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = ''): bool |
|
186 | + public function renewCache(string $cacheKey, int | string $ttl = 3600, string $namespace = ''): bool |
|
187 | 187 | { |
188 | 188 | $this->cacheer->cacheStore->renewCache($cacheKey, $ttl, $namespace); |
189 | 189 | $this->cacheer->syncState(); |
@@ -23,56 +23,56 @@ discard block |
||
23 | 23 | final class Cacheer implements CacheerInterface |
24 | 24 | { |
25 | 25 | /** |
26 | - * @var string |
|
27 | - */ |
|
26 | + * @var string |
|
27 | + */ |
|
28 | 28 | private string $message; |
29 | 29 | |
30 | 30 | /** |
31 | - * @var boolean |
|
32 | - */ |
|
31 | + * @var boolean |
|
32 | + */ |
|
33 | 33 | private bool $success; |
34 | 34 | |
35 | 35 | /** |
36 | - * @var boolean |
|
37 | - */ |
|
36 | + * @var boolean |
|
37 | + */ |
|
38 | 38 | private bool $formatted = false; |
39 | 39 | |
40 | 40 | /** |
41 | - * @var bool |
|
42 | - */ |
|
41 | + * @var bool |
|
42 | + */ |
|
43 | 43 | private bool $compression = false; |
44 | 44 | |
45 | 45 | /** |
46 | - * @var string|null |
|
47 | - */ |
|
46 | + * @var string|null |
|
47 | + */ |
|
48 | 48 | private ?string $encryptionKey = null; |
49 | 49 | |
50 | 50 | /** |
51 | - * @var FileCacheStore|DatabaseCacheStore|RedisCacheStore|ArrayCacheStore |
|
52 | - */ |
|
51 | + * @var FileCacheStore|DatabaseCacheStore|RedisCacheStore|ArrayCacheStore |
|
52 | + */ |
|
53 | 53 | public RedisCacheStore|DatabaseCacheStore|ArrayCacheStore|FileCacheStore $cacheStore; |
54 | 54 | |
55 | 55 | /** |
56 | - * @var array |
|
57 | - */ |
|
56 | + * @var array |
|
57 | + */ |
|
58 | 58 | public array $options = []; |
59 | 59 | |
60 | 60 | /** |
61 | - * @var CacheRetriever |
|
62 | - */ |
|
61 | + * @var CacheRetriever |
|
62 | + */ |
|
63 | 63 | private CacheRetriever $retriever; |
64 | 64 | |
65 | 65 | /** |
66 | - * @var CacheMutator |
|
67 | - */ |
|
66 | + * @var CacheMutator |
|
67 | + */ |
|
68 | 68 | private CacheMutator $mutator; |
69 | 69 | |
70 | 70 | /** |
71 | - * Cacheer constructor. |
|
72 | - * |
|
73 | - * @param array $options |
|
74 | - * @param bool $formatted |
|
75 | - * @throws RuntimeException|Exceptions\CacheFileException |
|
71 | + * Cacheer constructor. |
|
72 | + * |
|
73 | + * @param array $options |
|
74 | + * @param bool $formatted |
|
75 | + * @throws RuntimeException|Exceptions\CacheFileException |
|
76 | 76 | */ |
77 | 77 | public function __construct(array $options = [], bool $formatted = false) |
78 | 78 | { |
@@ -84,122 +84,122 @@ discard block |
||
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
87 | - * Adds data to the cache if it does not already exist. |
|
88 | - * |
|
89 | - * @param string $cacheKey |
|
90 | - * @param mixed $cacheData |
|
91 | - * @param string $namespace |
|
92 | - * @param int|string $ttl |
|
93 | - * @return bool |
|
94 | - */ |
|
87 | + * Adds data to the cache if it does not already exist. |
|
88 | + * |
|
89 | + * @param string $cacheKey |
|
90 | + * @param mixed $cacheData |
|
91 | + * @param string $namespace |
|
92 | + * @param int|string $ttl |
|
93 | + * @return bool |
|
94 | + */ |
|
95 | 95 | public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool |
96 | 96 | { |
97 | 97 | return $this->mutator->add($cacheKey, $cacheData, $namespace, $ttl); |
98 | 98 | } |
99 | 99 | |
100 | 100 | /** |
101 | - * Appends data to an existing cache item. |
|
102 | - * |
|
103 | - * @param string $cacheKey |
|
104 | - * @param mixed $cacheData |
|
105 | - * @param string $namespace |
|
106 | - * @return bool |
|
107 | - */ |
|
101 | + * Appends data to an existing cache item. |
|
102 | + * |
|
103 | + * @param string $cacheKey |
|
104 | + * @param mixed $cacheData |
|
105 | + * @param string $namespace |
|
106 | + * @return bool |
|
107 | + */ |
|
108 | 108 | public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = ''): bool |
109 | 109 | { |
110 | 110 | return $this->mutator->appendCache($cacheKey, $cacheData, $namespace); |
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
114 | - * Clears a specific cache item. |
|
115 | - * |
|
116 | - * @param string $cacheKey |
|
117 | - * @param string $namespace |
|
118 | - * @return bool |
|
119 | - */ |
|
114 | + * Clears a specific cache item. |
|
115 | + * |
|
116 | + * @param string $cacheKey |
|
117 | + * @param string $namespace |
|
118 | + * @return bool |
|
119 | + */ |
|
120 | 120 | public function clearCache(string $cacheKey, string $namespace = ''): bool |
121 | 121 | { |
122 | 122 | return $this->mutator->clearCache($cacheKey, $namespace); |
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | - * Decrements a cache item by a specified amount. |
|
127 | - * |
|
128 | - * @param string $cacheKey |
|
129 | - * @param int $amount |
|
130 | - * @param string $namespace |
|
131 | - * @return bool |
|
132 | - */ |
|
126 | + * Decrements a cache item by a specified amount. |
|
127 | + * |
|
128 | + * @param string $cacheKey |
|
129 | + * @param int $amount |
|
130 | + * @param string $namespace |
|
131 | + * @return bool |
|
132 | + */ |
|
133 | 133 | public function decrement(string $cacheKey, int $amount = 1, string $namespace = ''): bool |
134 | 134 | { |
135 | 135 | return $this->mutator->decrement($cacheKey, $amount, $namespace); |
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | - * Store data in the cache permanently. |
|
140 | - * |
|
141 | - * @param string $cacheKey |
|
142 | - * @param mixed $cacheData |
|
143 | - * @return bool |
|
144 | - */ |
|
139 | + * Store data in the cache permanently. |
|
140 | + * |
|
141 | + * @param string $cacheKey |
|
142 | + * @param mixed $cacheData |
|
143 | + * @return bool |
|
144 | + */ |
|
145 | 145 | public function forever(string $cacheKey, mixed $cacheData): bool |
146 | 146 | { |
147 | 147 | return $this->mutator->forever($cacheKey, $cacheData); |
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
151 | - * Flushes all cache items. |
|
152 | - * |
|
153 | - * @return bool |
|
154 | - */ |
|
151 | + * Flushes all cache items. |
|
152 | + * |
|
153 | + * @return bool |
|
154 | + */ |
|
155 | 155 | public function flushCache(): bool |
156 | 156 | { |
157 | 157 | return $this->mutator->flushCache(); |
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
161 | - * Retrieves a cache item and deletes it from the cache. |
|
162 | - * |
|
163 | - * @param string $cacheKey |
|
164 | - * @param string $namespace |
|
165 | - * @return mixed |
|
166 | - */ |
|
161 | + * Retrieves a cache item and deletes it from the cache. |
|
162 | + * |
|
163 | + * @param string $cacheKey |
|
164 | + * @param string $namespace |
|
165 | + * @return mixed |
|
166 | + */ |
|
167 | 167 | public function getAndForget(string $cacheKey, string $namespace = ''): mixed |
168 | 168 | { |
169 | 169 | return $this->retriever->getAndForget($cacheKey, $namespace); |
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
173 | - * Gets all items in a specific namespace. |
|
174 | - * |
|
175 | - * @param string $namespace |
|
176 | - * @return CacheDataFormatter|mixed |
|
177 | - */ |
|
173 | + * Gets all items in a specific namespace. |
|
174 | + * |
|
175 | + * @param string $namespace |
|
176 | + * @return CacheDataFormatter|mixed |
|
177 | + */ |
|
178 | 178 | public function getAll(string $namespace = ''): mixed |
179 | 179 | { |
180 | 180 | return $this->retriever->getAll($namespace); |
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
184 | - * Retrieves a single cache item. |
|
185 | - * |
|
186 | - * @param string $cacheKey |
|
187 | - * @param string $namespace |
|
188 | - * @param string|int $ttl |
|
189 | - * @return CacheDataFormatter|mixed |
|
190 | - */ |
|
184 | + * Retrieves a single cache item. |
|
185 | + * |
|
186 | + * @param string $cacheKey |
|
187 | + * @param string $namespace |
|
188 | + * @param string|int $ttl |
|
189 | + * @return CacheDataFormatter|mixed |
|
190 | + */ |
|
191 | 191 | public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed |
192 | 192 | { |
193 | 193 | return $this->retriever->getCache($cacheKey, $namespace, $ttl); |
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | - * Retrieves multiple cache items by their keys. |
|
198 | - * |
|
199 | - * @param array $cacheKeys |
|
200 | - * @param string $namespace |
|
201 | - * @param string|int $ttl |
|
202 | - * @return CacheDataFormatter|array |
|
197 | + * Retrieves multiple cache items by their keys. |
|
198 | + * |
|
199 | + * @param array $cacheKeys |
|
200 | + * @param string $namespace |
|
201 | + * @param string|int $ttl |
|
202 | + * @return CacheDataFormatter|array |
|
203 | 203 | */ |
204 | 204 | public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): CacheDataFormatter|array |
205 | 205 | { |
@@ -207,132 +207,132 @@ discard block |
||
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
210 | - * Checks if a cache item exists. |
|
211 | - * |
|
212 | - * @param string $cacheKey |
|
213 | - * @param string $namespace |
|
214 | - * @return bool |
|
215 | - */ |
|
210 | + * Checks if a cache item exists. |
|
211 | + * |
|
212 | + * @param string $cacheKey |
|
213 | + * @param string $namespace |
|
214 | + * @return bool |
|
215 | + */ |
|
216 | 216 | public function has(string $cacheKey, string $namespace = ''): bool |
217 | 217 | { |
218 | 218 | return $this->retriever->has($cacheKey, $namespace); |
219 | 219 | } |
220 | 220 | |
221 | 221 | /** |
222 | - * Increments a cache item by a specified amount. |
|
223 | - * |
|
224 | - * @param string $cacheKey |
|
225 | - * @param int $amount |
|
226 | - * @param string $namespace |
|
227 | - * @return bool |
|
228 | - */ |
|
222 | + * Increments a cache item by a specified amount. |
|
223 | + * |
|
224 | + * @param string $cacheKey |
|
225 | + * @param int $amount |
|
226 | + * @param string $namespace |
|
227 | + * @return bool |
|
228 | + */ |
|
229 | 229 | public function increment(string $cacheKey, int $amount = 1, string $namespace = ''): bool |
230 | 230 | { |
231 | 231 | return $this->mutator->increment($cacheKey, $amount, $namespace); |
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
235 | - * Checks if the last operation was successful. |
|
236 | - * |
|
237 | - * @return bool |
|
238 | - */ |
|
235 | + * Checks if the last operation was successful. |
|
236 | + * |
|
237 | + * @return bool |
|
238 | + */ |
|
239 | 239 | public function isSuccess(): bool |
240 | 240 | { |
241 | 241 | return $this->success; |
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
245 | - * Stores an item in the cache with a specific TTL. |
|
246 | - * |
|
247 | - * @param string $cacheKey |
|
248 | - * @param mixed $cacheData |
|
249 | - * @param string $namespace |
|
250 | - * @param string|int $ttl |
|
251 | - * @return bool |
|
252 | - */ |
|
245 | + * Stores an item in the cache with a specific TTL. |
|
246 | + * |
|
247 | + * @param string $cacheKey |
|
248 | + * @param mixed $cacheData |
|
249 | + * @param string $namespace |
|
250 | + * @param string|int $ttl |
|
251 | + * @return bool |
|
252 | + */ |
|
253 | 253 | public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600): bool |
254 | 254 | { |
255 | 255 | return $this->mutator->putCache($cacheKey, $cacheData, $namespace, $ttl); |
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
259 | - * Stores multiple items in the cache. |
|
260 | - * |
|
261 | - * @param array $items |
|
262 | - * @param string $namespace |
|
263 | - * @param integer $batchSize |
|
264 | - * @return bool |
|
265 | - */ |
|
259 | + * Stores multiple items in the cache. |
|
260 | + * |
|
261 | + * @param array $items |
|
262 | + * @param string $namespace |
|
263 | + * @param integer $batchSize |
|
264 | + * @return bool |
|
265 | + */ |
|
266 | 266 | public function putMany(array $items, string $namespace = '', int $batchSize = 100): bool |
267 | 267 | { |
268 | 268 | return $this->mutator->putMany($items, $namespace, $batchSize); |
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
272 | - * Renews the cache for a specific key with a new TTL. |
|
273 | - * |
|
274 | - * @param string $cacheKey |
|
275 | - * @param string|int $ttl |
|
276 | - * @param string $namespace |
|
277 | - * @return bool |
|
278 | - */ |
|
272 | + * Renews the cache for a specific key with a new TTL. |
|
273 | + * |
|
274 | + * @param string $cacheKey |
|
275 | + * @param string|int $ttl |
|
276 | + * @param string $namespace |
|
277 | + * @return bool |
|
278 | + */ |
|
279 | 279 | public function renewCache(string $cacheKey, string|int $ttl = 3600, string $namespace = ''): bool |
280 | 280 | { |
281 | 281 | return $this->mutator->renewCache($cacheKey, $ttl, $namespace); |
282 | 282 | } |
283 | 283 | |
284 | 284 | /** |
285 | - * Retrieves a cache item or executes a callback to store it if not found. |
|
286 | - * |
|
287 | - * @param string $cacheKey |
|
288 | - * @param int|string $ttl |
|
289 | - * @param Closure $callback |
|
290 | - * @return mixed |
|
291 | - */ |
|
285 | + * Retrieves a cache item or executes a callback to store it if not found. |
|
286 | + * |
|
287 | + * @param string $cacheKey |
|
288 | + * @param int|string $ttl |
|
289 | + * @param Closure $callback |
|
290 | + * @return mixed |
|
291 | + */ |
|
292 | 292 | public function remember(string $cacheKey, int|string $ttl, Closure $callback): mixed |
293 | 293 | { |
294 | 294 | return $this->retriever->remember($cacheKey, $ttl, $callback); |
295 | 295 | } |
296 | 296 | |
297 | 297 | /** |
298 | - * Retrieves a cache item or executes a callback to store it permanently if not found. |
|
299 | - * |
|
300 | - * @param string $cacheKey |
|
301 | - * @param Closure $callback |
|
302 | - * @return mixed |
|
303 | - */ |
|
298 | + * Retrieves a cache item or executes a callback to store it permanently if not found. |
|
299 | + * |
|
300 | + * @param string $cacheKey |
|
301 | + * @param Closure $callback |
|
302 | + * @return mixed |
|
303 | + */ |
|
304 | 304 | public function rememberForever(string $cacheKey, Closure $callback): mixed |
305 | 305 | { |
306 | 306 | return $this->retriever->rememberForever($cacheKey, $callback); |
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
310 | - * Returns a CacheConfig instance for configuration management. |
|
311 | - * |
|
312 | - * @return CacheConfig |
|
313 | - */ |
|
310 | + * Returns a CacheConfig instance for configuration management. |
|
311 | + * |
|
312 | + * @return CacheConfig |
|
313 | + */ |
|
314 | 314 | public function setConfig(): CacheConfig |
315 | 315 | { |
316 | 316 | return new CacheConfig($this); |
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
320 | - * Sets the cache driver based on the configuration. |
|
321 | - * |
|
322 | - * @return CacheDriver |
|
323 | - */ |
|
320 | + * Sets the cache driver based on the configuration. |
|
321 | + * |
|
322 | + * @return CacheDriver |
|
323 | + */ |
|
324 | 324 | public function setDriver(): CacheDriver |
325 | 325 | { |
326 | 326 | return new CacheDriver($this); |
327 | 327 | } |
328 | 328 | |
329 | 329 | /** |
330 | - * Sets a message for the cache operation. |
|
331 | - * |
|
332 | - * @param string $message |
|
333 | - * @param boolean $success |
|
334 | - * @return void |
|
335 | - */ |
|
330 | + * Sets a message for the cache operation. |
|
331 | + * |
|
332 | + * @param string $message |
|
333 | + * @param boolean $success |
|
334 | + * @return void |
|
335 | + */ |
|
336 | 336 | private function setMessage(string $message, bool $success): void |
337 | 337 | { |
338 | 338 | $this->message = $message; |
@@ -340,10 +340,10 @@ discard block |
||
340 | 340 | } |
341 | 341 | |
342 | 342 | /** |
343 | - * Retrieves the message from the last operation. |
|
344 | - * |
|
345 | - * @return string |
|
346 | - */ |
|
343 | + * Retrieves the message from the last operation. |
|
344 | + * |
|
345 | + * @return string |
|
346 | + */ |
|
347 | 347 | public function getMessage(): string |
348 | 348 | { |
349 | 349 | return $this->message; |
@@ -392,32 +392,32 @@ discard block |
||
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
395 | - * Enables or disables the formatter for cache data. |
|
396 | - * |
|
397 | - * @return void |
|
398 | - */ |
|
395 | + * Enables or disables the formatter for cache data. |
|
396 | + * |
|
397 | + * @return void |
|
398 | + */ |
|
399 | 399 | public function useFormatter(): void |
400 | 400 | { |
401 | 401 | $this->formatted = !$this->formatted; |
402 | 402 | } |
403 | 403 | |
404 | 404 | /** |
405 | - * Validates the options provided for the Cacheer instance. |
|
406 | - * |
|
407 | - * @param array $options |
|
408 | - * @return void |
|
409 | - */ |
|
405 | + * Validates the options provided for the Cacheer instance. |
|
406 | + * |
|
407 | + * @param array $options |
|
408 | + * @return void |
|
409 | + */ |
|
410 | 410 | private function validateOptions(array $options): void |
411 | 411 | { |
412 | 412 | $this->options = $options; |
413 | 413 | } |
414 | 414 | |
415 | 415 | /** |
416 | - * Enable or disable data compression |
|
417 | - * |
|
418 | - * @param bool $status |
|
419 | - * @return $this |
|
420 | - */ |
|
416 | + * Enable or disable data compression |
|
417 | + * |
|
418 | + * @param bool $status |
|
419 | + * @return $this |
|
420 | + */ |
|
421 | 421 | public function useCompression(bool $status = true): Cacheer |
422 | 422 | { |
423 | 423 | $this->compression = $status; |
@@ -425,11 +425,11 @@ discard block |
||
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
428 | - * Enable encryption for cached data |
|
429 | - * |
|
430 | - * @param string $key |
|
431 | - * @return $this |
|
432 | - */ |
|
428 | + * Enable encryption for cached data |
|
429 | + * |
|
430 | + * @param string $key |
|
431 | + * @return $this |
|
432 | + */ |
|
433 | 433 | public function useEncryption(string $key): Cacheer |
434 | 434 | { |
435 | 435 | $this->encryptionKey = $key; |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | /** |
51 | 51 | * @var FileCacheStore|DatabaseCacheStore|RedisCacheStore|ArrayCacheStore |
52 | 52 | */ |
53 | - public RedisCacheStore|DatabaseCacheStore|ArrayCacheStore|FileCacheStore $cacheStore; |
|
53 | + public RedisCacheStore | DatabaseCacheStore | ArrayCacheStore | FileCacheStore $cacheStore; |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * @var array |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | * @param int|string $ttl |
93 | 93 | * @return bool |
94 | 94 | */ |
95 | - public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600): bool |
|
95 | + public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600): bool |
|
96 | 96 | { |
97 | 97 | return $this->mutator->add($cacheKey, $cacheData, $namespace, $ttl); |
98 | 98 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | * @param string|int $ttl |
189 | 189 | * @return CacheDataFormatter|mixed |
190 | 190 | */ |
191 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed |
|
191 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600): mixed |
|
192 | 192 | { |
193 | 193 | return $this->retriever->getCache($cacheKey, $namespace, $ttl); |
194 | 194 | } |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * @param string|int $ttl |
202 | 202 | * @return CacheDataFormatter|array |
203 | 203 | */ |
204 | - public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): CacheDataFormatter|array |
|
204 | + public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600): CacheDataFormatter | array |
|
205 | 205 | { |
206 | 206 | return $this->retriever->getMany($cacheKeys, $namespace, $ttl); |
207 | 207 | } |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * @param string|int $ttl |
251 | 251 | * @return bool |
252 | 252 | */ |
253 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600): bool |
|
253 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600): bool |
|
254 | 254 | { |
255 | 255 | return $this->mutator->putCache($cacheKey, $cacheData, $namespace, $ttl); |
256 | 256 | } |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | * @param string $namespace |
277 | 277 | * @return bool |
278 | 278 | */ |
279 | - public function renewCache(string $cacheKey, string|int $ttl = 3600, string $namespace = ''): bool |
|
279 | + public function renewCache(string $cacheKey, string | int $ttl = 3600, string $namespace = ''): bool |
|
280 | 280 | { |
281 | 281 | return $this->mutator->renewCache($cacheKey, $ttl, $namespace); |
282 | 282 | } |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | * @param Closure $callback |
290 | 290 | * @return mixed |
291 | 291 | */ |
292 | - public function remember(string $cacheKey, int|string $ttl, Closure $callback): mixed |
|
292 | + public function remember(string $cacheKey, int | string $ttl, Closure $callback): mixed |
|
293 | 293 | { |
294 | 294 | return $this->retriever->remember($cacheKey, $ttl, $callback); |
295 | 295 | } |