@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @param string|int $ttl |
| 30 | 30 | * @return bool |
| 31 | 31 | */ |
| 32 | - public function store(string $cacheKey, mixed $cacheData, string $namespace, string|int $ttl = 3600) |
|
| 32 | + public function store(string $cacheKey, mixed $cacheData, string $namespace, string | int $ttl = 3600) |
|
| 33 | 33 | { |
| 34 | 34 | if (!empty($this->retrieve($cacheKey, $namespace))) { |
| 35 | 35 | return $this->update($cacheKey, $cacheData, $namespace); |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * @param string $namespace |
| 175 | 175 | * @return bool |
| 176 | 176 | */ |
| 177 | - public function renew(string $cacheKey, string|int $ttl, string $namespace = '') |
|
| 177 | + public function renew(string $cacheKey, string | int $ttl, string $namespace = '') |
|
| 178 | 178 | { |
| 179 | 179 | $currentTime = date('Y-m-d H:i:s'); |
| 180 | 180 | if (!$this->hasValidCache($cacheKey, $namespace, $currentTime)) { |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | |
| 184 | 184 | $query = $this->getRenewExpirationQueryWithDriver(); |
| 185 | 185 | $stmt = $this->connection->prepare($query); |
| 186 | - $stmt->bindValue(':ttl', (int) $ttl, PDO::PARAM_INT); |
|
| 186 | + $stmt->bindValue(':ttl', (int)$ttl, PDO::PARAM_INT); |
|
| 187 | 187 | $stmt->bindValue(':cacheKey', $cacheKey); |
| 188 | 188 | $stmt->bindValue(':namespace', $namespace); |
| 189 | 189 | $stmt->bindValue(':currentTime', $currentTime); |
@@ -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'); |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | * @param string|int $ttl |
| 159 | 159 | * @return string |
| 160 | 160 | */ |
| 161 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
| 161 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
| 162 | 162 | { |
| 163 | 163 | |
| 164 | 164 | $ttl = CacheFileHelper::ttl($ttl, $this->defaultTTL); |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @param string|int $ttl |
| 182 | 182 | * @return array |
| 183 | 183 | */ |
| 184 | - public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600) |
|
| 184 | + public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600) |
|
| 185 | 185 | { |
| 186 | 186 | $ttl = CacheFileHelper::ttl($ttl, $this->defaultTTL); |
| 187 | 187 | $results = []; |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * @param string|int $ttl |
| 224 | 224 | * @return void |
| 225 | 225 | */ |
| 226 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) |
|
| 226 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) |
|
| 227 | 227 | { |
| 228 | 228 | $cacheFile = $this->buildCacheFilePath($cacheKey, $namespace); |
| 229 | 229 | $data = $this->fileManager->serialize($cacheData); |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | * @param string $namespace |
| 257 | 257 | * @return void |
| 258 | 258 | */ |
| 259 | - public function renewCache(string $cacheKey, string|int $ttl, string $namespace = '') |
|
| 259 | + public function renewCache(string $cacheKey, string | int $ttl, string $namespace = '') |
|
| 260 | 260 | { |
| 261 | 261 | $cacheData = $this->getCache($cacheKey, $namespace); |
| 262 | 262 | if ($cacheData) { |
@@ -346,12 +346,12 @@ discard block |
||
| 346 | 346 | { |
| 347 | 347 | $flushAfterSeconds = CacheFileHelper::convertExpirationToSeconds($flushAfter); |
| 348 | 348 | |
| 349 | - if(!$this->fileManager->fileExists($this->lastFlushTimeFile)) { |
|
| 349 | + if (!$this->fileManager->fileExists($this->lastFlushTimeFile)) { |
|
| 350 | 350 | $this->fileManager->writeFile($this->lastFlushTimeFile, time()); |
| 351 | 351 | return; |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | - $lastFlushTime = (int) $this->fileManager->readFile($this->lastFlushTimeFile); |
|
| 354 | + $lastFlushTime = (int)$this->fileManager->readFile($this->lastFlushTimeFile); |
|
| 355 | 355 | |
| 356 | 356 | if ((time() - $lastFlushTime) >= $flushAfterSeconds) { |
| 357 | 357 | $this->flushCache(); |
@@ -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 | } |
@@ -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 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. |
@@ -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."); |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | * @param int|string $ttl |
| 80 | 80 | * @return bool |
| 81 | 81 | */ |
| 82 | - public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
|
| 82 | + public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600) |
|
| 83 | 83 | { |
| 84 | 84 | if (!empty($this->getCache($cacheKey, $namespace))) { |
| 85 | 85 | return true; |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | * @param string|int $ttl |
| 204 | 204 | * @return CacheDataFormatter|mixed |
| 205 | 205 | */ |
| 206 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
| 206 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
| 207 | 207 | { |
| 208 | 208 | $cacheData = $this->cacheStore->getCache($cacheKey, $namespace, $ttl); |
| 209 | 209 | $this->setMessage($this->cacheStore->getMessage(), $this->cacheStore->isSuccess()); |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * @param string|int $ttl |
| 224 | 224 | * @return CacheDataFormatter|array |
| 225 | 225 | */ |
| 226 | - public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600) |
|
| 226 | + public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600) |
|
| 227 | 227 | { |
| 228 | 228 | $cachedData = $this->cacheStore->getMany($cacheKeys, $namespace, $ttl); |
| 229 | 229 | $this->setMessage($this->cacheStore->getMessage(), $this->cacheStore->isSuccess()); |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | { |
| 263 | 263 | $cacheData = $this->getCache($cacheKey, $namespace); |
| 264 | 264 | |
| 265 | - if(!empty($cacheData) && is_numeric($cacheData)) { |
|
| 265 | + if (!empty($cacheData) && is_numeric($cacheData)) { |
|
| 266 | 266 | $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace); |
| 267 | 267 | $this->setMessage($this->getMessage(), $this->isSuccess()); |
| 268 | 268 | return true; |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * @param string|int $ttl |
| 291 | 291 | * @return void |
| 292 | 292 | */ |
| 293 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) |
|
| 293 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) |
|
| 294 | 294 | { |
| 295 | 295 | $data = CacheerHelper::prepareForStorage($cacheData, $this->compression, $this->encryptionKey); |
| 296 | 296 | $this->cacheStore->putCache($cacheKey, $data, $namespace, $ttl); |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | * @param string $namespace |
| 319 | 319 | * @return void |
| 320 | 320 | */ |
| 321 | - public function renewCache(string $cacheKey, string|int $ttl = 3600, string $namespace = '') |
|
| 321 | + public function renewCache(string $cacheKey, string | int $ttl = 3600, string $namespace = '') |
|
| 322 | 322 | { |
| 323 | 323 | $this->cacheStore->renewCache($cacheKey, $ttl, $namespace); |
| 324 | 324 | |
@@ -337,11 +337,11 @@ discard block |
||
| 337 | 337 | * @param Closure $callback |
| 338 | 338 | * @return mixed |
| 339 | 339 | */ |
| 340 | - public function remember(string $cacheKey, int|string $ttl, Closure $callback) |
|
| 340 | + public function remember(string $cacheKey, int | string $ttl, Closure $callback) |
|
| 341 | 341 | { |
| 342 | 342 | $cachedData = $this->getCache($cacheKey, ttl: $ttl); |
| 343 | 343 | |
| 344 | - if(!empty($cachedData)) { |
|
| 344 | + if (!empty($cachedData)) { |
|
| 345 | 345 | return $cachedData; |
| 346 | 346 | } |
| 347 | 347 | |