@@ -9,8 +9,8 @@ |
||
9 | 9 | */ |
10 | 10 | interface CacheerInterface |
11 | 11 | { |
12 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600); |
|
13 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600); |
|
12 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600); |
|
13 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600); |
|
14 | 14 | public function flushCache(); |
15 | 15 | public function clearCache(string $cacheKey, string $namespace = ''); |
16 | 16 | public function has(string $cacheKey, string $namespace = ''); |
@@ -19,7 +19,7 @@ |
||
19 | 19 | */ |
20 | 20 | public static function serialize(mixed $data, bool $serialize = true) |
21 | 21 | { |
22 | - if($serialize) { |
|
22 | + if ($serialize) { |
|
23 | 23 | return serialize($data); |
24 | 24 | } |
25 | 25 |
@@ -37,7 +37,7 @@ |
||
37 | 37 | */ |
38 | 38 | private static function auth() |
39 | 39 | { |
40 | - if(is_string(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']) && REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'] !== '') { |
|
40 | + if (is_string(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']) && REDIS_CONNECTION_CONFIG['REDIS_PASSWORD'] !== '') { |
|
41 | 41 | self::$redis->auth(REDIS_CONNECTION_CONFIG['REDIS_PASSWORD']); |
42 | 42 | } |
43 | 43 | } |
@@ -77,7 +77,7 @@ |
||
77 | 77 | */ |
78 | 78 | public function serialize(mixed $data, bool $serealize = true) |
79 | 79 | { |
80 | - if($serealize) { |
|
80 | + if ($serealize) { |
|
81 | 81 | return serialize($data); |
82 | 82 | } |
83 | 83 | return unserialize($data); |
@@ -53,12 +53,12 @@ discard block |
||
53 | 53 | * @param string|int $ttl |
54 | 54 | * @return mixed |
55 | 55 | */ |
56 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
56 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
57 | 57 | { |
58 | 58 | $fullCacheKey = $this->buildKey($cacheKey, $namespace); |
59 | 59 | $cacheData = $this->redis->get($fullCacheKey); |
60 | 60 | |
61 | - if($cacheData) { |
|
61 | + if ($cacheData) { |
|
62 | 62 | $this->setMessage("Cache retrieved successfully", true); |
63 | 63 | $this->logger->debug("{$this->getMessage()} from redis driver."); |
64 | 64 | return CacheRedisHelper::serialize($cacheData, false); |
@@ -77,12 +77,12 @@ discard block |
||
77 | 77 | * @param string|int|null $ttl |
78 | 78 | * @return mixed |
79 | 79 | */ |
80 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int|null $ttl = null) |
|
80 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int | null $ttl = null) |
|
81 | 81 | { |
82 | 82 | $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
83 | 83 | $serializedData = CacheRedisHelper::serialize($cacheData); |
84 | 84 | |
85 | - $result = $ttl ? $this->redis->setex($cacheFullKey, (int) $ttl, $serializedData) |
|
85 | + $result = $ttl ? $this->redis->setex($cacheFullKey, (int)$ttl, $serializedData) |
|
86 | 86 | : $this->redis->set($cacheFullKey, $serializedData); |
87 | 87 | |
88 | 88 | if ($result) { |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
107 | 107 | |
108 | 108 | |
109 | - if($this->redis->del($cacheFullKey) > 0) { |
|
109 | + if ($this->redis->del($cacheFullKey) > 0) { |
|
110 | 110 | $this->setMessage("Cache cleared successfully", true); |
111 | 111 | } else { |
112 | 112 | $this->setMessage("Something went wrong. Please, try again.", false); |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | { |
126 | 126 | $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
127 | 127 | |
128 | - if($this->redis->exists($cacheFullKey) > 0) { |
|
128 | + if ($this->redis->exists($cacheFullKey) > 0) { |
|
129 | 129 | $this->setMessage("Cache Key: {$cacheKey} exists!", true); |
130 | 130 | } else { |
131 | 131 | $this->setMessage("Cache Key: {$cacheKey} does not exists!", false); |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @param string $namespace |
141 | 141 | * @return void |
142 | 142 | */ |
143 | - public function renewCache(string $cacheKey, string|int $ttl, string $namespace = '') |
|
143 | + public function renewCache(string $cacheKey, string | int $ttl, string $namespace = '') |
|
144 | 144 | { |
145 | 145 | $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
146 | 146 | $dump = $this->getDump($cacheFullKey); |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | $processedCount = 0; |
201 | 201 | $itemCount = count($items); |
202 | 202 | |
203 | - while($processedCount < $itemCount) |
|
203 | + while ($processedCount < $itemCount) |
|
204 | 204 | { |
205 | 205 | |
206 | 206 | $batchItems = array_slice($items, $processedCount, $batchSize); |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | public function flushCache() |
217 | 217 | { |
218 | 218 | |
219 | - if($this->redis->flushall()) { |
|
219 | + if ($this->redis->flushall()) { |
|
220 | 220 | $this->setMessage("Cache flushed successfully", true); |
221 | 221 | } else { |
222 | 222 | $this->setMessage("Something went wrong. Please, try again.", false); |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | */ |
270 | 270 | private function processBatchItems(array $batchItems, string $namespace) |
271 | 271 | { |
272 | - foreach($batchItems as $item) { |
|
272 | + foreach ($batchItems as $item) { |
|
273 | 273 | CacheRedisHelper::validateCacheItem($item); |
274 | 274 | $cacheKey = $item['cacheKey']; |
275 | 275 | $cacheData = $item['cacheData']; |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | * @param mixed $dump |
295 | 295 | * @return bool |
296 | 296 | */ |
297 | - private function restoreKey(string $fullKey, string|int $ttl, mixed $dump) |
|
297 | + private function restoreKey(string $fullKey, string | int $ttl, mixed $dump) |
|
298 | 298 | { |
299 | 299 | try { |
300 | 300 | $this->redis->restore($fullKey, $ttl * 1000, $dump, 'REPLACE'); |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @param string|int $ttl |
48 | 48 | * @return mixed |
49 | 49 | */ |
50 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
50 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
51 | 51 | { |
52 | 52 | $cacheData = $this->retrieveCache($cacheKey, $namespace); |
53 | 53 | if ($cacheData) { |
@@ -66,9 +66,9 @@ discard block |
||
66 | 66 | * @param string|int $ttl |
67 | 67 | * @return bool |
68 | 68 | */ |
69 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) |
|
69 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) |
|
70 | 70 | { |
71 | - if($this->storeCache($cacheKey, $cacheData, $namespace, $ttl)){ |
|
71 | + if ($this->storeCache($cacheKey, $cacheData, $namespace, $ttl)) { |
|
72 | 72 | $this->logger->debug("{$this->getMessage()} from database driver."); |
73 | 73 | return true; |
74 | 74 | } |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | public function clearCache(string $cacheKey, string $namespace = '') |
152 | 152 | { |
153 | 153 | $data = $this->cacheRepository->clear($cacheKey, $namespace); |
154 | - if($data) { |
|
154 | + if ($data) { |
|
155 | 155 | $this->setMessage("Cache deleted successfully!", true); |
156 | 156 | } else { |
157 | 157 | $this->setMessage("Cache does not exists!", false); |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | */ |
166 | 166 | public function flushCache() |
167 | 167 | { |
168 | - if($this->cacheRepository->flush()){ |
|
168 | + if ($this->cacheRepository->flush()) { |
|
169 | 169 | $this->setMessage("Flush finished successfully", true); |
170 | 170 | } else { |
171 | 171 | $this->setMessage("Something went wrong. Please, try again.", false); |
@@ -193,10 +193,10 @@ discard block |
||
193 | 193 | * @param integer $ttl |
194 | 194 | * @return bool |
195 | 195 | */ |
196 | - private function storeCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) |
|
196 | + private function storeCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) |
|
197 | 197 | { |
198 | 198 | $data = $this->cacheRepository->store($cacheKey, $cacheData, $namespace, $ttl); |
199 | - if($data) { |
|
199 | + if ($data) { |
|
200 | 200 | $this->setMessage("Cache Stored Successfully", true); |
201 | 201 | return true; |
202 | 202 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | private function updateCache(string $cacheKey, mixed $cacheData, string $namespace = '') |
215 | 215 | { |
216 | 216 | $data = $this->cacheRepository->update($cacheKey, $cacheData, $namespace); |
217 | - if($data) { |
|
217 | + if ($data) { |
|
218 | 218 | $this->setMessage("Cache updated successfully.", true); |
219 | 219 | return true; |
220 | 220 | } |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | * @param string $namespace |
229 | 229 | * @return bool |
230 | 230 | */ |
231 | - private function renew(string $cacheKey, string|int $ttl = 3600, string $namespace = '') |
|
231 | + private function renew(string $cacheKey, string | int $ttl = 3600, string $namespace = '') |
|
232 | 232 | { |
233 | 233 | $cacheData = $this->getCache($cacheKey, $namespace); |
234 | 234 | if ($cacheData) { |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | */ |
251 | 251 | private function processBatchItems(array $batchItems, string $namespace) |
252 | 252 | { |
253 | - foreach($batchItems as $item) { |
|
253 | + foreach ($batchItems as $item) { |
|
254 | 254 | CacheDatabaseHelper::validateCacheItem($item); |
255 | 255 | $cacheKey = $item['cacheKey']; |
256 | 256 | $cacheData = $item['cacheData']; |
@@ -17,7 +17,7 @@ |
||
17 | 17 | */ |
18 | 18 | public static function create(string $message = "", int $code = 0, ?Exception $previous = null, array $details = []) |
19 | 19 | { |
20 | - return new self(self::getBefore() . ": " .$message, $code, $previous, $details); |
|
20 | + return new self(self::getBefore() . ": " . $message, $code, $previous, $details); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 |
@@ -15,7 +15,7 @@ |
||
15 | 15 | */ |
16 | 16 | public static function create(string $message = "", int $code = 0, ?Exception $previous = null, array $details = []) |
17 | 17 | { |
18 | - return new self(self::getBefore() . ": " .$message, $code, $previous, $details); |
|
18 | + return new self(self::getBefore() . ": " . $message, $code, $previous, $details); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | $Cacheer->putCache($cacheKey, $userProfile, ttl: 300); |
20 | 20 | |
21 | 21 | // Recuperando dados do cache |
22 | -if($Cacheer->isSuccess()){ |
|
22 | +if ($Cacheer->isSuccess()) { |
|
23 | 23 | echo "Cache Found: "; |
24 | 24 | print_r($Cacheer->getCache($cacheKey)); |
25 | 25 | } else { |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | // Renovando os dados do cache |
30 | 30 | $Cacheer->renewCache($cacheKey, 3600); |
31 | 31 | |
32 | -if($Cacheer->isSuccess()){ |
|
32 | +if ($Cacheer->isSuccess()) { |
|
33 | 33 | echo $Cacheer->getMessage() . PHP_EOL; |
34 | 34 | } else { |
35 | 35 | echo $Cacheer->getMessage() . PHP_EOL; |