@@ -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(); |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | * @param int|string $ttl |
| 124 | 124 | * @return mixed |
| 125 | 125 | */ |
| 126 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
| 126 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
| 127 | 127 | { |
| 128 | 128 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
| 129 | 129 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | $expirationTime = $cacheData['expirationTime'] ?? 0; |
| 138 | 138 | $now = time(); |
| 139 | 139 | |
| 140 | - if($expirationTime !== 0 && $now >= $expirationTime) { |
|
| 140 | + if ($expirationTime !== 0 && $now >= $expirationTime) { |
|
| 141 | 141 | list($np, $key) = explode(':', $arrayStoreKey); |
| 142 | 142 | $this->clearCache($key, $np); |
| 143 | 143 | $this->setMessage("cacheKey: {$key} has expired.", false); |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | * @param string|int $ttl |
| 157 | 157 | * @return array |
| 158 | 158 | */ |
| 159 | - public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600) |
|
| 159 | + public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600) |
|
| 160 | 160 | { |
| 161 | 161 | $results = []; |
| 162 | 162 | foreach ($cacheKeys as $cacheKey) { |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | { |
| 187 | 187 | $cacheData = $this->getCache($cacheKey, $namespace); |
| 188 | 188 | |
| 189 | - if(!empty($cacheData) && is_numeric($cacheData)) { |
|
| 189 | + if (!empty($cacheData) && is_numeric($cacheData)) { |
|
| 190 | 190 | $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace); |
| 191 | 191 | $this->setMessage($this->getMessage(), $this->isSuccess()); |
| 192 | 192 | return true; |
@@ -218,7 +218,7 @@ discard block |
||
| 218 | 218 | * @param int|string $ttl |
| 219 | 219 | * @return bool |
| 220 | 220 | */ |
| 221 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
|
| 221 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600) |
|
| 222 | 222 | { |
| 223 | 223 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
| 224 | 224 | |
@@ -257,12 +257,12 @@ discard block |
||
| 257 | 257 | * @param string $namespace |
| 258 | 258 | * @return void |
| 259 | 259 | */ |
| 260 | - public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = '') |
|
| 260 | + public function renewCache(string $cacheKey, int | string $ttl = 3600, string $namespace = '') |
|
| 261 | 261 | { |
| 262 | 262 | $arrayStoreKey = $this->buildArrayKey($cacheKey, $namespace); |
| 263 | 263 | |
| 264 | 264 | if (isset($this->arrayStore[$arrayStoreKey])) { |
| 265 | - $ttlSeconds = is_numeric($ttl) ? (int) $ttl : strtotime($ttl) - time(); |
|
| 265 | + $ttlSeconds = is_numeric($ttl) ? (int)$ttl : strtotime($ttl) - time(); |
|
| 266 | 266 | $this->arrayStore[$arrayStoreKey]['expirationTime'] = time() + $ttlSeconds; |
| 267 | 267 | $this->setMessage("cacheKey: {$cacheKey} renewed successfully", true); |
| 268 | 268 | $this->logger->debug("{$this->getMessage()} from array driver."); |
@@ -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 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | * @param int|string $ttl |
| 71 | 71 | * @return bool |
| 72 | 72 | */ |
| 73 | - public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
|
| 73 | + public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600) |
|
| 74 | 74 | { |
| 75 | 75 | if (!empty($this->getCache($cacheKey, $namespace))) { |
| 76 | 76 | return true; |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * @param string|int $ttl |
| 161 | 161 | * @return CacheDataFormatter|mixed |
| 162 | 162 | */ |
| 163 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
| 163 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
| 164 | 164 | { |
| 165 | 165 | $cacheData = $this->cacheStore->getCache($cacheKey, $namespace, $ttl); |
| 166 | 166 | $this->setMessage($this->cacheStore->getMessage(), $this->cacheStore->isSuccess()); |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | * @param string|int $ttl |
| 179 | 179 | * @return CacheDataFormatter|array |
| 180 | 180 | */ |
| 181 | - public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600) |
|
| 181 | + public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600) |
|
| 182 | 182 | { |
| 183 | 183 | $cachedData = $this->cacheStore->getMany($cacheKeys, $namespace, $ttl); |
| 184 | 184 | $this->setMessage($this->cacheStore->getMessage(), $this->cacheStore->isSuccess()); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | { |
| 214 | 214 | $cacheData = $this->getCache($cacheKey, $namespace); |
| 215 | 215 | |
| 216 | - if(!empty($cacheData) && is_numeric($cacheData)) { |
|
| 216 | + if (!empty($cacheData) && is_numeric($cacheData)) { |
|
| 217 | 217 | $this->putCache($cacheKey, (int)($cacheData + $amount), $namespace); |
| 218 | 218 | $this->setMessage($this->getMessage(), $this->isSuccess()); |
| 219 | 219 | return true; |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | * @param string|int $ttl |
| 238 | 238 | * @return void |
| 239 | 239 | */ |
| 240 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) |
|
| 240 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) |
|
| 241 | 241 | { |
| 242 | 242 | $data = CacheerHelper::prepareForStorage($cacheData, $this->compression, $this->encryptionKey); |
| 243 | 243 | $this->cacheStore->putCache($cacheKey, $data, $namespace, $ttl); |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | * @param string $namespace |
| 262 | 262 | * @return void |
| 263 | 263 | */ |
| 264 | - public function renewCache(string $cacheKey, string|int $ttl = 3600, string $namespace = '') |
|
| 264 | + public function renewCache(string $cacheKey, string | int $ttl = 3600, string $namespace = '') |
|
| 265 | 265 | { |
| 266 | 266 | $this->cacheStore->renewCache($cacheKey, $ttl, $namespace); |
| 267 | 267 | |
@@ -278,11 +278,11 @@ discard block |
||
| 278 | 278 | * @param Closure $callback |
| 279 | 279 | * @return mixed |
| 280 | 280 | */ |
| 281 | - public function remember(string $cacheKey, int|string $ttl, Closure $callback) |
|
| 281 | + public function remember(string $cacheKey, int | string $ttl, Closure $callback) |
|
| 282 | 282 | { |
| 283 | 283 | $cachedData = $this->getCache($cacheKey, ttl: $ttl); |
| 284 | 284 | |
| 285 | - if(!empty($cachedData)) { |
|
| 285 | + if (!empty($cachedData)) { |
|
| 286 | 286 | return $cachedData; |
| 287 | 287 | } |
| 288 | 288 | |