@@ -91,7 +91,7 @@ |
||
| 91 | 91 | */ |
| 92 | 92 | public function serialize(mixed $data, bool $serialize = true) |
| 93 | 93 | { |
| 94 | - if($serialize) { |
|
| 94 | + if ($serialize) { |
|
| 95 | 95 | return serialize($data); |
| 96 | 96 | } |
| 97 | 97 | return unserialize($data); |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * @param string|int $ttl |
| 119 | 119 | * @return mixed |
| 120 | 120 | */ |
| 121 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
| 121 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
| 122 | 122 | { |
| 123 | 123 | $fullCacheKey = $this->buildKey($cacheKey, $namespace); |
| 124 | 124 | $cacheData = $this->redis->get($fullCacheKey); |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | * @param string|int $ttl |
| 140 | 140 | * @return array |
| 141 | 141 | */ |
| 142 | - public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600) |
|
| 142 | + public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600) |
|
| 143 | 143 | { |
| 144 | 144 | $results = []; |
| 145 | 145 | foreach ($cacheKeys as $cacheKey) { |
@@ -227,12 +227,12 @@ discard block |
||
| 227 | 227 | * @param string|int|null $ttl |
| 228 | 228 | * @return mixed |
| 229 | 229 | */ |
| 230 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int|null $ttl = null) |
|
| 230 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int | null $ttl = null) |
|
| 231 | 231 | { |
| 232 | 232 | $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
| 233 | 233 | $serializedData = CacheRedisHelper::serialize($cacheData); |
| 234 | 234 | |
| 235 | - $result = $ttl ? $this->redis->setex($cacheFullKey, (int) $ttl, $serializedData) |
|
| 235 | + $result = $ttl ? $this->redis->setex($cacheFullKey, (int)$ttl, $serializedData) |
|
| 236 | 236 | : $this->redis->set($cacheFullKey, $serializedData); |
| 237 | 237 | |
| 238 | 238 | if ($result) { |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | * @param string $namespace |
| 270 | 270 | * @return void |
| 271 | 271 | */ |
| 272 | - public function renewCache(string $cacheKey, string|int $ttl, string $namespace = '') |
|
| 272 | + public function renewCache(string $cacheKey, string | int $ttl, string $namespace = '') |
|
| 273 | 273 | { |
| 274 | 274 | $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
| 275 | 275 | $dump = $this->getDump($cacheFullKey); |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | * @param mixed $dump |
| 298 | 298 | * @return bool |
| 299 | 299 | */ |
| 300 | - private function restoreKey(string $fullKey, string|int $ttl, mixed $dump) |
|
| 300 | + private function restoreKey(string $fullKey, string | int $ttl, mixed $dump) |
|
| 301 | 301 | { |
| 302 | 302 | try { |
| 303 | 303 | $this->redis->restore($fullKey, $ttl * 1000, $dump, 'REPLACE'); |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | public function clearCache(string $cacheKey, string $namespace = '') |
| 69 | 69 | { |
| 70 | 70 | $data = $this->cacheRepository->clear($cacheKey, $namespace); |
| 71 | - if($data) { |
|
| 71 | + if ($data) { |
|
| 72 | 72 | $this->setMessage("Cache deleted successfully!", true); |
| 73 | 73 | } else { |
| 74 | 74 | $this->setMessage("Cache does not exists!", false); |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | */ |
| 83 | 83 | public function flushCache() |
| 84 | 84 | { |
| 85 | - if($this->cacheRepository->flush()){ |
|
| 85 | + if ($this->cacheRepository->flush()) { |
|
| 86 | 86 | $this->setMessage("Flush finished successfully", true); |
| 87 | 87 | } else { |
| 88 | 88 | $this->setMessage("Something went wrong. Please, try again.", false); |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | * @param string|int $ttl |
| 99 | 99 | * @return mixed |
| 100 | 100 | */ |
| 101 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
| 101 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
| 102 | 102 | { |
| 103 | 103 | $cacheData = $this->retrieveCache($cacheKey, $namespace); |
| 104 | 104 | if ($cacheData) { |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | * @param string|int $ttl |
| 118 | 118 | * @return array |
| 119 | 119 | */ |
| 120 | - public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600) |
|
| 120 | + public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600) |
|
| 121 | 121 | { |
| 122 | 122 | $cacheData = []; |
| 123 | 123 | foreach ($cacheKeys as $cacheKey) { |
@@ -190,9 +190,9 @@ discard block |
||
| 190 | 190 | * @param string|int $ttl |
| 191 | 191 | * @return bool |
| 192 | 192 | */ |
| 193 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) |
|
| 193 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) |
|
| 194 | 194 | { |
| 195 | - if($this->storeCache($cacheKey, $cacheData, $namespace, $ttl)){ |
|
| 195 | + if ($this->storeCache($cacheKey, $cacheData, $namespace, $ttl)) { |
|
| 196 | 196 | $this->logger->debug("{$this->getMessage()} from database driver."); |
| 197 | 197 | return true; |
| 198 | 198 | } |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | */ |
| 224 | 224 | private function processBatchItems(array $batchItems, string $namespace) |
| 225 | 225 | { |
| 226 | - foreach($batchItems as $item) { |
|
| 226 | + foreach ($batchItems as $item) { |
|
| 227 | 227 | CacheDatabaseHelper::validateCacheItem($item); |
| 228 | 228 | $cacheKey = $item['cacheKey']; |
| 229 | 229 | $cacheData = $item['cacheData']; |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | * @param string $namespace |
| 239 | 239 | * @return bool |
| 240 | 240 | */ |
| 241 | - private function renew(string $cacheKey, string|int $ttl = 3600, string $namespace = '') |
|
| 241 | + private function renew(string $cacheKey, string | int $ttl = 3600, string $namespace = '') |
|
| 242 | 242 | { |
| 243 | 243 | $cacheData = $this->getCache($cacheKey, $namespace); |
| 244 | 244 | if ($cacheData) { |
@@ -281,10 +281,10 @@ discard block |
||
| 281 | 281 | * @param integer $ttl |
| 282 | 282 | * @return bool |
| 283 | 283 | */ |
| 284 | - private function storeCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) |
|
| 284 | + private function storeCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) |
|
| 285 | 285 | { |
| 286 | 286 | $data = $this->cacheRepository->store($cacheKey, $cacheData, $namespace, $ttl); |
| 287 | - if($data) { |
|
| 287 | + if ($data) { |
|
| 288 | 288 | $this->setMessage("Cache Stored Successfully", true); |
| 289 | 289 | return true; |
| 290 | 290 | } |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | private function updateCache(string $cacheKey, mixed $cacheData, string $namespace = '') |
| 302 | 302 | { |
| 303 | 303 | $data = $this->cacheRepository->update($cacheKey, $cacheData, $namespace); |
| 304 | - if($data) { |
|
| 304 | + if ($data) { |
|
| 305 | 305 | $this->setMessage("Cache updated successfully.", true); |
| 306 | 306 | return true; |
| 307 | 307 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | * @param int|string $ttl |
| 143 | 143 | * @return mixed |
| 144 | 144 | */ |
| 145 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
| 145 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
| 146 | 146 | { |
| 147 | 147 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
| 148 | 148 | |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | * @param string|int $ttl |
| 232 | 232 | * @return array |
| 233 | 233 | */ |
| 234 | - public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600) |
|
| 234 | + public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600) |
|
| 235 | 235 | { |
| 236 | 236 | $results = []; |
| 237 | 237 | foreach ($cacheKeys as $cacheKey) { |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | { |
| 266 | 266 | $cacheData = $this->getCache($cacheKey, $namespace); |
| 267 | 267 | |
| 268 | - if(!empty($cacheData) && is_numeric($cacheData)) { |
|
| 268 | + if (!empty($cacheData) && is_numeric($cacheData)) { |
|
| 269 | 269 | $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace); |
| 270 | 270 | $this->setMessage($this->getMessage(), $this->isSuccess()); |
| 271 | 271 | return true; |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | * @param int|string $ttl |
| 304 | 304 | * @return bool |
| 305 | 305 | */ |
| 306 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
|
| 306 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600) |
|
| 307 | 307 | { |
| 308 | 308 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
| 309 | 309 | |
@@ -346,12 +346,12 @@ discard block |
||
| 346 | 346 | * @param string $namespace |
| 347 | 347 | * @return void |
| 348 | 348 | */ |
| 349 | - public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = '') |
|
| 349 | + public function renewCache(string $cacheKey, int | string $ttl = 3600, string $namespace = '') |
|
| 350 | 350 | { |
| 351 | 351 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
| 352 | 352 | |
| 353 | 353 | if (isset($this->arrayStore[$arrayStoreKey])) { |
| 354 | - $ttlSeconds = is_numeric($ttl) ? (int) $ttl : strtotime($ttl) - time(); |
|
| 354 | + $ttlSeconds = is_numeric($ttl) ? (int)$ttl : strtotime($ttl) - time(); |
|
| 355 | 355 | $this->arrayStore[$arrayStoreKey]['expirationTime'] = time() + $ttlSeconds; |
| 356 | 356 | $this->setMessage("cacheKey: {$cacheKey} renewed successfully", true); |
| 357 | 357 | $this->logger->debug("{$this->getMessage()} from array driver."); |
@@ -52,7 +52,7 @@ |
||
| 52 | 52 | return; |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | - $lastFlushTime = (int) $this->fileManager->readFile($this->lastFlushTimeFile); |
|
| 55 | + $lastFlushTime = (int)$this->fileManager->readFile($this->lastFlushTimeFile); |
|
| 56 | 56 | |
| 57 | 57 | if ((time() - $lastFlushTime) >= $flushAfterSeconds) { |
| 58 | 58 | $this->flushCache(); |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @param string|int $ttl Lifetime in seconds (default: 3600) |
| 53 | 53 | * @return mixed Returns the cached data or null if not found |
| 54 | 54 | */ |
| 55 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600); |
|
| 55 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600); |
|
| 56 | 56 | |
| 57 | 57 | /** |
| 58 | 58 | * Retrieves multiple cache items by their keys. |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | * @param string|int $ttl Lifetime in seconds (default: 3600) |
| 63 | 63 | * @return CacheDataFormatter|mixed Returns a formatter with the retrieved items |
| 64 | 64 | */ |
| 65 | - public function getMany(array $cacheKeys, string $namespace, string|int $ttl = 3600); |
|
| 65 | + public function getMany(array $cacheKeys, string $namespace, string | int $ttl = 3600); |
|
| 66 | 66 | |
| 67 | 67 | /** |
| 68 | 68 | * Checks if a cache item exists. |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * @param string|int $ttl Lifetime in seconds (default: 3600) |
| 83 | 83 | * @return bool True on success, false on failure |
| 84 | 84 | */ |
| 85 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600); |
|
| 85 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600); |
|
| 86 | 86 | |
| 87 | 87 | /** |
| 88 | 88 | * Stores multiple items in the cache. |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | * @param string|int $ttl |
| 179 | 179 | * @return string |
| 180 | 180 | */ |
| 181 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
| 181 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
| 182 | 182 | { |
| 183 | 183 | |
| 184 | 184 | $ttl = CacheFileHelper::ttl($ttl, $this->defaultTTL); |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | * @param string|int $ttl |
| 264 | 264 | * @return mixed |
| 265 | 265 | */ |
| 266 | - public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600) |
|
| 266 | + public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600) |
|
| 267 | 267 | { |
| 268 | 268 | $ttl = CacheFileHelper::ttl($ttl, $this->defaultTTL); |
| 269 | 269 | $results = []; |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | * @param string|int $ttl |
| 310 | 310 | * @return void |
| 311 | 311 | */ |
| 312 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) |
|
| 312 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) |
|
| 313 | 313 | { |
| 314 | 314 | $cacheFile = $this->buildCacheFilePath($cacheKey, $namespace); |
| 315 | 315 | $data = $this->fileManager->serialize($cacheData); |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | * @param string $namespace |
| 347 | 347 | * @return void |
| 348 | 348 | */ |
| 349 | - public function renewCache(string $cacheKey, string|int $ttl, string $namespace = '') |
|
| 349 | + public function renewCache(string $cacheKey, string | int $ttl, string $namespace = '') |
|
| 350 | 350 | { |
| 351 | 351 | $cacheData = $this->getCache($cacheKey, $namespace); |
| 352 | 352 | if ($cacheData) { |
@@ -92,11 +92,11 @@ discard block |
||
| 92 | 92 | public function test_remember_saves_and_recover_values() |
| 93 | 93 | { |
| 94 | 94 | $this->cache->flushCache(); |
| 95 | - $value = $this->cache->remember('remember_test_key', 60, function () { |
|
| 95 | + $value = $this->cache->remember('remember_test_key', 60, function() { |
|
| 96 | 96 | return 'valor_teste'; |
| 97 | 97 | }); |
| 98 | 98 | $this->assertEquals('valor_teste', $value); |
| 99 | - $cachedValue = $this->cache->remember('remember_test_key', 60, function(){ |
|
| 99 | + $cachedValue = $this->cache->remember('remember_test_key', 60, function() { |
|
| 100 | 100 | return 'novo_valor'; |
| 101 | 101 | }); |
| 102 | 102 | $this->assertEquals('valor_teste', $cachedValue); |
@@ -105,11 +105,11 @@ discard block |
||
| 105 | 105 | public function test_remember_forever_saves_value_indefinitely() |
| 106 | 106 | { |
| 107 | 107 | $this->cache->flushCache(); |
| 108 | - $value = $this->cache->rememberForever('remember_forever_key', function () { |
|
| 108 | + $value = $this->cache->rememberForever('remember_forever_key', function() { |
|
| 109 | 109 | return 'valor_eterno'; |
| 110 | 110 | }); |
| 111 | 111 | $this->assertEquals('valor_eterno', $value); |
| 112 | - $cachedValue = $this->cache->rememberForever('remember_forever_key', function () { |
|
| 112 | + $cachedValue = $this->cache->rememberForever('remember_forever_key', function() { |
|
| 113 | 113 | return 'novo_valor'; |
| 114 | 114 | }); |
| 115 | 115 | $this->assertEquals('valor_eterno', $cachedValue); |
@@ -37,12 +37,12 @@ discard block |
||
| 37 | 37 | * @param int|string $ttl |
| 38 | 38 | * @return mixed |
| 39 | 39 | */ |
| 40 | - public function getCache(string $cacheKey, string $namespace = '', int|string $ttl = 3600) |
|
| 40 | + public function getCache(string $cacheKey, string $namespace = '', int | string $ttl = 3600) |
|
| 41 | 41 | { |
| 42 | 42 | $cacheData = $this->cacheer->cacheStore->getCache($cacheKey, $namespace, $ttl); |
| 43 | 43 | $this->cacheer->syncState(); |
| 44 | 44 | |
| 45 | - if ($this->cacheer->isSuccess() && ($this->cacheer->isCompressionEnabled() || $this->cacheer->getEncryptionKey() !== null)) { |
|
| 45 | + if ($this->cacheer->isSuccess() && ($this->cacheer->isCompressionEnabled() || $this->cacheer->getEncryptionKey() !== null)) { |
|
| 46 | 46 | $cacheData = CacheerHelper::recoverFromStorage($cacheData, $this->cacheer->isCompressionEnabled(), $this->cacheer->getEncryptionKey()); |
| 47 | 47 | } |
| 48 | 48 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | * @param int|string $ttl |
| 58 | 58 | * @return array|CacheDataFormatter |
| 59 | 59 | */ |
| 60 | - public function getMany(array $cacheKeys, string $namespace = '', int|string $ttl = 3600) |
|
| 60 | + public function getMany(array $cacheKeys, string $namespace = '', int | string $ttl = 3600) |
|
| 61 | 61 | { |
| 62 | 62 | $cachedData = $this->cacheer->cacheStore->getMany($cacheKeys, $namespace, $ttl); |
| 63 | 63 | $this->cacheer->syncState(); |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | * @param Closure $callback |
| 120 | 120 | * @return mixed |
| 121 | 121 | */ |
| 122 | - public function remember(string $cacheKey, int|string $ttl, Closure $callback) |
|
| 122 | + public function remember(string $cacheKey, int | string $ttl, Closure $callback) |
|
| 123 | 123 | { |
| 124 | 124 | $cachedData = $this->getCache($cacheKey, ttl: $ttl); |
| 125 | 125 | |