@@ -90,7 +90,7 @@ |
||
90 | 90 | /** |
91 | 91 | * @var FileCacheStore|DatabaseCacheStore|RedisCacheStore|ArrayCacheStore |
92 | 92 | */ |
93 | - public RedisCacheStore|DatabaseCacheStore|ArrayCacheStore|FileCacheStore $cacheStore; |
|
93 | + public RedisCacheStore | DatabaseCacheStore | ArrayCacheStore | FileCacheStore $cacheStore; |
|
94 | 94 | |
95 | 95 | /** |
96 | 96 | * @var array |
@@ -60,7 +60,7 @@ |
||
60 | 60 | ->build(); |
61 | 61 | |
62 | 62 | $flushFile = FlushHelper::pathFor('redis', 'app:'); |
63 | - file_put_contents($flushFile, (string) (time() - 3600)); |
|
63 | + file_put_contents($flushFile, (string)(time() - 3600)); |
|
64 | 64 | |
65 | 65 | // seed |
66 | 66 | $seed = new Cacheer(OptionBuilder::forRedis()->setNamespace('app:')->build()); |
@@ -74,7 +74,7 @@ |
||
74 | 74 | |
75 | 75 | // Pre-create an old last flush file to force a flush on init |
76 | 76 | $flushFile = FlushHelper::pathFor('db', $this->table); |
77 | - file_put_contents($flushFile, (string) (time() - 3600)); |
|
77 | + file_put_contents($flushFile, (string)(time() - 3600)); |
|
78 | 78 | |
79 | 79 | // Seed data using a cache without flushAfter |
80 | 80 | $seed = new Cacheer(OptionBuilder::forDatabase()->table($this->table)->build()); |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | return $this; |
51 | 51 | } |
52 | 52 | |
53 | - return new TimeBuilder(function ($formattedTime) { |
|
53 | + return new TimeBuilder(function($formattedTime) { |
|
54 | 54 | $this->expirationTime = $formattedTime; |
55 | 55 | }, $this); |
56 | 56 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | return $this; |
69 | 69 | } |
70 | 70 | |
71 | - return new TimeBuilder(function ($formattedTime) { |
|
71 | + return new TimeBuilder(function($formattedTime) { |
|
72 | 72 | $this->flushAfter = $formattedTime; |
73 | 73 | }, $this); |
74 | 74 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | public function flushCache(): void |
34 | 34 | { |
35 | 35 | ($this->flushCallback)(); |
36 | - @file_put_contents($this->lastFlushTimeFile, (string) time()); |
|
36 | + @file_put_contents($this->lastFlushTimeFile, (string)time()); |
|
37 | 37 | } |
38 | 38 | |
39 | 39 | /** |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | if (!isset($options['flushAfter'])) { |
47 | 47 | return; |
48 | 48 | } |
49 | - $this->scheduleFlush((string) $options['flushAfter']); |
|
49 | + $this->scheduleFlush((string)$options['flushAfter']); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -55,18 +55,18 @@ discard block |
||
55 | 55 | */ |
56 | 56 | private function scheduleFlush(string $flushAfter): void |
57 | 57 | { |
58 | - $flushAfterSeconds = (int) CacheFileHelper::convertExpirationToSeconds($flushAfter); |
|
58 | + $flushAfterSeconds = (int)CacheFileHelper::convertExpirationToSeconds($flushAfter); |
|
59 | 59 | |
60 | 60 | if (!file_exists($this->lastFlushTimeFile)) { |
61 | - @file_put_contents($this->lastFlushTimeFile, (string) time()); |
|
61 | + @file_put_contents($this->lastFlushTimeFile, (string)time()); |
|
62 | 62 | return; |
63 | 63 | } |
64 | 64 | |
65 | - $lastFlushTime = (int) @file_get_contents($this->lastFlushTimeFile); |
|
65 | + $lastFlushTime = (int)@file_get_contents($this->lastFlushTimeFile); |
|
66 | 66 | |
67 | 67 | if ((time() - $lastFlushTime) >= $flushAfterSeconds) { |
68 | 68 | $this->flushCache(); |
69 | - @file_put_contents($this->lastFlushTimeFile, (string) time()); |
|
69 | + @file_put_contents($this->lastFlushTimeFile, (string)time()); |
|
70 | 70 | } |
71 | 71 | } |
72 | 72 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | return $this; |
51 | 51 | } |
52 | 52 | |
53 | - return new TimeBuilder(function ($formattedTime) { |
|
53 | + return new TimeBuilder(function($formattedTime) { |
|
54 | 54 | $this->expirationTime = $formattedTime; |
55 | 55 | }, $this); |
56 | 56 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | return $this; |
69 | 69 | } |
70 | 70 | |
71 | - return new TimeBuilder(function ($formattedTime) { |
|
71 | + return new TimeBuilder(function($formattedTime) { |
|
72 | 72 | $this->flushAfter = $formattedTime; |
73 | 73 | }, $this); |
74 | 74 | } |
@@ -62,11 +62,11 @@ discard block |
||
62 | 62 | MigrationManager::migrate($pdo, $table); |
63 | 63 | |
64 | 64 | if (!empty($options['expirationTime'])) { |
65 | - $this->defaultTTL = (int) CacheFileHelper::convertExpirationToSeconds((string) $options['expirationTime']); |
|
65 | + $this->defaultTTL = (int)CacheFileHelper::convertExpirationToSeconds((string)$options['expirationTime']); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | $lastFlushFile = FlushHelper::pathFor('db', $table); |
69 | - $this->flusher = new GenericFlusher($lastFlushFile, function () { |
|
69 | + $this->flusher = new GenericFlusher($lastFlushFile, function() { |
|
70 | 70 | $this->flushCache(); |
71 | 71 | }); |
72 | 72 | $this->flusher->handleAutoFlush($options); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | public function clearCache(string $cacheKey, string $namespace = ''): void |
105 | 105 | { |
106 | 106 | $data = $this->cacheRepository->clear($cacheKey, $namespace); |
107 | - if($data) { |
|
107 | + if ($data) { |
|
108 | 108 | $this->setMessage("Cache deleted successfully!", true); |
109 | 109 | } else { |
110 | 110 | $this->setMessage("Cache does not exists!", false); |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | */ |
121 | 121 | public function flushCache(): void |
122 | 122 | { |
123 | - if($this->cacheRepository->flush()){ |
|
123 | + if ($this->cacheRepository->flush()) { |
|
124 | 124 | $this->setMessage("Flush finished successfully", true); |
125 | 125 | } else { |
126 | 126 | $this->setMessage("Something went wrong. Please, try again.", false); |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | * @param string|int $ttl |
139 | 139 | * @return mixed |
140 | 140 | */ |
141 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed |
|
141 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600): mixed |
|
142 | 142 | { |
143 | 143 | $cacheData = $this->retrieveCache($cacheKey, $namespace); |
144 | 144 | if ($cacheData) { |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * @param string|int $ttl |
179 | 179 | * @return array |
180 | 180 | */ |
181 | - public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): array |
|
181 | + public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600): array |
|
182 | 182 | { |
183 | 183 | $cacheData = []; |
184 | 184 | foreach ($cacheKeys as $cacheKey) { |
@@ -268,17 +268,17 @@ discard block |
||
268 | 268 | * @param string|int $ttl |
269 | 269 | * @return bool |
270 | 270 | */ |
271 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600): bool |
|
271 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600): bool |
|
272 | 272 | { |
273 | 273 | $ttlToUse = $ttl; |
274 | 274 | if ($this->defaultTTL !== null && ($ttl === null || (int)$ttl === 3600)) { |
275 | 275 | $ttlToUse = $this->defaultTTL; |
276 | 276 | } |
277 | 277 | if (is_string($ttlToUse)) { |
278 | - $ttlToUse = (int) CacheFileHelper::convertExpirationToSeconds($ttlToUse); |
|
278 | + $ttlToUse = (int)CacheFileHelper::convertExpirationToSeconds($ttlToUse); |
|
279 | 279 | } |
280 | 280 | |
281 | - if($this->storeCache($cacheKey, $cacheData, $namespace, $ttlToUse)){ |
|
281 | + if ($this->storeCache($cacheKey, $cacheData, $namespace, $ttlToUse)) { |
|
282 | 282 | $this->logger->debug("{$this->getMessage()} from database driver."); |
283 | 283 | return true; |
284 | 284 | } |
@@ -313,7 +313,7 @@ discard block |
||
313 | 313 | */ |
314 | 314 | private function processBatchItems(array $batchItems, string $namespace): void |
315 | 315 | { |
316 | - foreach($batchItems as $item) { |
|
316 | + foreach ($batchItems as $item) { |
|
317 | 317 | CacheDatabaseHelper::validateCacheItem($item); |
318 | 318 | $cacheKey = $item['cacheKey']; |
319 | 319 | $cacheData = $item['cacheData']; |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | * @param string $namespace |
331 | 331 | * @return bool |
332 | 332 | */ |
333 | - private function renew(string $cacheKey, string|int $ttl = 3600, string $namespace = ''): bool |
|
333 | + private function renew(string $cacheKey, string | int $ttl = 3600, string $namespace = ''): bool |
|
334 | 334 | { |
335 | 335 | $cacheData = $this->getCache($cacheKey, $namespace); |
336 | 336 | if ($cacheData) { |
@@ -378,10 +378,10 @@ discard block |
||
378 | 378 | * @param string|int $ttl |
379 | 379 | * @return bool |
380 | 380 | */ |
381 | - private function storeCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600): bool |
|
381 | + private function storeCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600): bool |
|
382 | 382 | { |
383 | 383 | $data = $this->cacheRepository->store($cacheKey, $cacheData, $namespace, $ttl); |
384 | - if($data) { |
|
384 | + if ($data) { |
|
385 | 385 | $this->setMessage("Cache Stored Successfully", true); |
386 | 386 | return true; |
387 | 387 | } |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | private function updateCache(string $cacheKey, mixed $cacheData, string $namespace = ''): bool |
401 | 401 | { |
402 | 402 | $data = $this->cacheRepository->update($cacheKey, $cacheData, $namespace); |
403 | - if($data) { |
|
403 | + if ($data) { |
|
404 | 404 | $this->setMessage("Cache updated successfully.", true); |
405 | 405 | return true; |
406 | 406 | } |
@@ -61,17 +61,17 @@ discard block |
||
61 | 61 | |
62 | 62 | // OptionBuilder support |
63 | 63 | if (!empty($options['namespace'])) { |
64 | - $this->namespace = (string) $options['namespace']; |
|
64 | + $this->namespace = (string)$options['namespace']; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | // Default TTL from options |
68 | 68 | if (!empty($options['expirationTime'])) { |
69 | - $this->defaultTTL = (int) CacheFileHelper::convertExpirationToSeconds((string) $options['expirationTime']); |
|
69 | + $this->defaultTTL = (int)CacheFileHelper::convertExpirationToSeconds((string)$options['expirationTime']); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | // Auto-flush support |
73 | 73 | $lastFlushFile = FlushHelper::pathFor('redis', $this->namespace ?: 'default'); |
74 | - $this->flusher = new GenericFlusher($lastFlushFile, function () { |
|
74 | + $this->flusher = new GenericFlusher($lastFlushFile, function() { |
|
75 | 75 | $this->flushCache(); |
76 | 76 | }); |
77 | 77 | $this->flusher->handleAutoFlush($options); |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | $added = 0; |
165 | 165 | foreach ($keys as $key) { |
166 | 166 | // Accept either raw key or "namespace:key" |
167 | - $added += (int) $this->redis->sadd($setKey, [$key]); |
|
167 | + $added += (int)$this->redis->sadd($setKey, [$key]); |
|
168 | 168 | } |
169 | 169 | $this->setMessage("Tagged successfully", true); |
170 | 170 | $this->logger->debug("{$this->getMessage()} from redis driver."); |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * @param string|int $ttl |
203 | 203 | * @return mixed |
204 | 204 | */ |
205 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600): mixed |
|
205 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600): mixed |
|
206 | 206 | { |
207 | 207 | $fullCacheKey = $this->buildKey($cacheKey, $namespace); |
208 | 208 | $cacheData = $this->redis->get($fullCacheKey); |
@@ -257,7 +257,7 @@ discard block |
||
257 | 257 | * @param string|int $ttl |
258 | 258 | * @return array |
259 | 259 | */ |
260 | - public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600): array |
|
260 | + public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600): array |
|
261 | 261 | { |
262 | 262 | $results = []; |
263 | 263 | foreach ($cacheKeys as $cacheKey) { |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | * @param string|int|null $ttl |
358 | 358 | * @return Status|null |
359 | 359 | */ |
360 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int|null $ttl = null): ?Status |
|
360 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int | null $ttl = null): ?Status |
|
361 | 361 | { |
362 | 362 | $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
363 | 363 | $serializedData = CacheRedisHelper::serialize($cacheData); |
@@ -368,10 +368,10 @@ discard block |
||
368 | 368 | $ttlToUse = $this->defaultTTL; |
369 | 369 | } |
370 | 370 | if (is_string($ttlToUse)) { |
371 | - $ttlToUse = (int) CacheFileHelper::convertExpirationToSeconds($ttlToUse); |
|
371 | + $ttlToUse = (int)CacheFileHelper::convertExpirationToSeconds($ttlToUse); |
|
372 | 372 | } |
373 | 373 | |
374 | - $result = $ttlToUse ? $this->redis->setex($cacheFullKey, (int) $ttlToUse, $serializedData) |
|
374 | + $result = $ttlToUse ? $this->redis->setex($cacheFullKey, (int)$ttlToUse, $serializedData) |
|
375 | 375 | : $this->redis->set($cacheFullKey, $serializedData); |
376 | 376 | |
377 | 377 | if ($result) { |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | * @return void |
414 | 414 | * @throws CacheRedisException |
415 | 415 | */ |
416 | - public function renewCache(string $cacheKey, string|int $ttl, string $namespace = ''): void |
|
416 | + public function renewCache(string $cacheKey, string | int $ttl, string $namespace = ''): void |
|
417 | 417 | { |
418 | 418 | $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
419 | 419 | $dump = $this->getDump($cacheFullKey); |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | * @return bool |
445 | 445 | * @throws CacheRedisException |
446 | 446 | */ |
447 | - private function restoreKey(string $fullKey, string|int $ttl, mixed $dump): bool |
|
447 | + private function restoreKey(string $fullKey, string | int $ttl, mixed $dump): bool |
|
448 | 448 | { |
449 | 449 | try { |
450 | 450 | $this->redis->restore($fullKey, $ttl * 1000, $dump, 'REPLACE'); |