@@ -10,9 +10,9 @@ discard block |
||
10 | 10 | { |
11 | 11 | |
12 | 12 | /** |
13 | - * @param string $dir |
|
14 | - * @return void |
|
15 | - */ |
|
13 | + * @param string $dir |
|
14 | + * @return void |
|
15 | + */ |
|
16 | 16 | public function createDirectory(string $dir) |
17 | 17 | { |
18 | 18 | if ((!file_exists($dir) || !is_dir($dir)) && !mkdir($dir, 0777, true)) { |
@@ -21,10 +21,10 @@ discard block |
||
21 | 21 | } |
22 | 22 | |
23 | 23 | /** |
24 | - * @param string $filename |
|
25 | - * @param string $data |
|
26 | - * @return void |
|
27 | - */ |
|
24 | + * @param string $filename |
|
25 | + * @param string $data |
|
26 | + * @return void |
|
27 | + */ |
|
28 | 28 | public function writeFile(string $filename, string $data) |
29 | 29 | { |
30 | 30 | if (!@file_put_contents($filename, $data, LOCK_EX)) { |
@@ -33,9 +33,9 @@ discard block |
||
33 | 33 | } |
34 | 34 | |
35 | 35 | /** |
36 | - * @param string $filename |
|
37 | - * @return string |
|
38 | - */ |
|
36 | + * @param string $filename |
|
37 | + * @return string |
|
38 | + */ |
|
39 | 39 | public function readFile(string $filename) |
40 | 40 | { |
41 | 41 | if (!file_exists($filename)) { |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | } |
46 | 46 | |
47 | 47 | /** |
48 | - * @param string $filename |
|
49 | - * @return void |
|
50 | - */ |
|
48 | + * @param string $filename |
|
49 | + * @return void |
|
50 | + */ |
|
51 | 51 | public function removeFile(string $filename) |
52 | 52 | { |
53 | 53 | if (file_exists($filename)) { |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
59 | - * @param string $dir |
|
60 | - * @return void |
|
61 | - */ |
|
59 | + * @param string $dir |
|
60 | + * @return void |
|
61 | + */ |
|
62 | 62 | public function clearDirectory(string $dir) |
63 | 63 | { |
64 | 64 | $iterator = new RecursiveIteratorIterator( |
@@ -72,9 +72,9 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
75 | - * @param mixed $data |
|
76 | - * @param bool $serealize |
|
77 | - */ |
|
75 | + * @param mixed $data |
|
76 | + * @param bool $serealize |
|
77 | + */ |
|
78 | 78 | public function serialize(mixed $data, bool $serealize = true) |
79 | 79 | { |
80 | 80 | if($serealize) { |
@@ -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); |
@@ -16,93 +16,93 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class RedisCacheStore implements CacheerInterface |
18 | 18 | { |
19 | - /** @var */ |
|
20 | - private $redis; |
|
19 | + /** @var */ |
|
20 | + private $redis; |
|
21 | 21 | |
22 | - /** @param string $namespace */ |
|
23 | - private string $namespace = ''; |
|
22 | + /** @param string $namespace */ |
|
23 | + private string $namespace = ''; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var CacheLogger |
|
27 | - */ |
|
28 | - private $logger = null; |
|
25 | + /** |
|
26 | + * @var CacheLogger |
|
27 | + */ |
|
28 | + private $logger = null; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - private string $message = ''; |
|
30 | + /** |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + private string $message = ''; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @var boolean |
|
37 | - */ |
|
38 | - private bool $success = false; |
|
35 | + /** |
|
36 | + * @var boolean |
|
37 | + */ |
|
38 | + private bool $success = false; |
|
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function __construct(string $logPath) |
|
45 | - { |
|
41 | + /** |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function __construct(string $logPath) |
|
45 | + { |
|
46 | 46 | $this->redis = RedisCacheManager::connect(); |
47 | 47 | $this->logger = new CacheLogger($logPath); |
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * @param string $cacheKey |
|
52 | - * @param string $namespace |
|
53 | - * @param string|int $ttl |
|
54 | - * @return mixed |
|
55 | - */ |
|
56 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
57 | - { |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * @param string $cacheKey |
|
52 | + * @param string $namespace |
|
53 | + * @param string|int $ttl |
|
54 | + * @return mixed |
|
55 | + */ |
|
56 | + public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
57 | + { |
|
58 | 58 | $fullCacheKey = $this->buildKey($cacheKey, $namespace); |
59 | 59 | $cacheData = $this->redis->get($fullCacheKey); |
60 | 60 | |
61 | 61 | if($cacheData) { |
62 | - $this->setMessage("Cache retrieved successfully", true); |
|
63 | - $this->logger->debug("{$this->getMessage()} from redis driver."); |
|
64 | - return CacheRedisHelper::serialize($cacheData, false); |
|
62 | + $this->setMessage("Cache retrieved successfully", true); |
|
63 | + $this->logger->debug("{$this->getMessage()} from redis driver."); |
|
64 | + return CacheRedisHelper::serialize($cacheData, false); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | $this->setMessage("CacheData not found, does not exists or expired", false); |
68 | 68 | $this->logger->info("{$this->getMessage()} from redis driver."); |
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Armazena um item no cache Redis, com suporte a namespace e TTL opcional. |
|
73 | - * |
|
74 | - * @param string $cacheKey |
|
75 | - * @param mixed $cacheData |
|
76 | - * @param string $namespace |
|
77 | - * @param string|int|null $ttl |
|
78 | - * @return mixed |
|
79 | - */ |
|
80 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int|null $ttl = null) |
|
81 | - { |
|
82 | - $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
|
83 | - $serializedData = CacheRedisHelper::serialize($cacheData); |
|
84 | - |
|
85 | - $result = $ttl ? $this->redis->setex($cacheFullKey, (int) $ttl, $serializedData) |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Armazena um item no cache Redis, com suporte a namespace e TTL opcional. |
|
73 | + * |
|
74 | + * @param string $cacheKey |
|
75 | + * @param mixed $cacheData |
|
76 | + * @param string $namespace |
|
77 | + * @param string|int|null $ttl |
|
78 | + * @return mixed |
|
79 | + */ |
|
80 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int|null $ttl = null) |
|
81 | + { |
|
82 | + $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
|
83 | + $serializedData = CacheRedisHelper::serialize($cacheData); |
|
84 | + |
|
85 | + $result = $ttl ? $this->redis->setex($cacheFullKey, (int) $ttl, $serializedData) |
|
86 | 86 | : $this->redis->set($cacheFullKey, $serializedData); |
87 | 87 | |
88 | - if ($result) { |
|
89 | - $this->setMessage("Cache stored successfully", true); |
|
90 | - } else { |
|
91 | - $this->setMessage("Failed to store cache", false); |
|
92 | - } |
|
88 | + if ($result) { |
|
89 | + $this->setMessage("Cache stored successfully", true); |
|
90 | + } else { |
|
91 | + $this->setMessage("Failed to store cache", false); |
|
92 | + } |
|
93 | 93 | |
94 | - $this->logger->debug("{$this->getMessage()} from Redis driver."); |
|
95 | - return $result; |
|
96 | - } |
|
94 | + $this->logger->debug("{$this->getMessage()} from Redis driver."); |
|
95 | + return $result; |
|
96 | + } |
|
97 | 97 | |
98 | 98 | |
99 | - /** |
|
100 | - * @param string $cacheKey |
|
101 | - * @param string $namespace |
|
102 | - * @return bool |
|
103 | - */ |
|
104 | - public function clearCache(string $cacheKey, string $namespace = '') |
|
105 | - { |
|
99 | + /** |
|
100 | + * @param string $cacheKey |
|
101 | + * @param string $namespace |
|
102 | + * @return bool |
|
103 | + */ |
|
104 | + public function clearCache(string $cacheKey, string $namespace = '') |
|
105 | + { |
|
106 | 106 | $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
107 | 107 | |
108 | 108 | |
@@ -114,107 +114,107 @@ discard block |
||
114 | 114 | |
115 | 115 | |
116 | 116 | $this->logger->debug("{$this->getMessage()} from redis driver."); |
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @param string $cacheKey |
|
121 | - * @param string $namespace |
|
122 | - * @return void |
|
123 | - */ |
|
124 | - public function has(string $cacheKey, string $namespace = '') |
|
125 | - { |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @param string $cacheKey |
|
121 | + * @param string $namespace |
|
122 | + * @return void |
|
123 | + */ |
|
124 | + public function has(string $cacheKey, string $namespace = '') |
|
125 | + { |
|
126 | 126 | $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
127 | 127 | |
128 | 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); |
132 | - } |
|
132 | + } |
|
133 | 133 | |
134 | 134 | $this->logger->debug("{$this->getMessage()} from redis driver."); |
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @param string $cacheKey |
|
139 | - * @param string|int $ttl |
|
140 | - * @param string $namespace |
|
141 | - * @return void |
|
142 | - */ |
|
143 | - public function renewCache(string $cacheKey, string|int $ttl, string $namespace = '') |
|
144 | - { |
|
145 | - $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
|
146 | - $dump = $this->getDump($cacheFullKey); |
|
147 | - |
|
148 | - if (!$dump) { |
|
149 | - $this->setMessage("Cache Key: {$cacheKey} not found.", false); |
|
150 | - $this->logger->warning("{$this->getMessage()} from Redis driver."); |
|
151 | - return; |
|
152 | - } |
|
153 | - |
|
154 | - $this->clearCache($cacheFullKey); |
|
155 | - |
|
156 | - if ($this->restoreKey($cacheFullKey, $ttl, $dump)) { |
|
157 | - $this->setMessage("Cache Key: {$cacheKey} renewed successfully.", true); |
|
158 | - $this->logger->debug("{$this->getMessage()} from Redis driver."); |
|
159 | - } else { |
|
160 | - $this->setMessage("Failed to renew cache key: {$cacheKey}.", false); |
|
161 | - $this->logger->error("{$this->getMessage()} from Redis driver."); |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * @param string $cacheKey |
|
168 | - * @param mixed $cacheData |
|
169 | - * @param string $namespace |
|
170 | - * @return void |
|
171 | - */ |
|
172 | - public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = '') |
|
173 | - { |
|
174 | - $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
|
175 | - $existingData = $this->getCache($cacheFullKey); |
|
176 | - |
|
177 | - $mergedCacheData = CacheRedisHelper::arrayIdentifier($existingData, $cacheData); |
|
178 | - |
|
179 | - $serializedData = CacheRedisHelper::serialize($mergedCacheData); |
|
180 | - |
|
181 | - if ($this->redis->set($cacheFullKey, $serializedData)) { |
|
182 | - $this->setMessage("Cache appended successfully", true); |
|
183 | - } else { |
|
184 | - $this->setMessage("Something went wrong. Please, try again.", false); |
|
185 | - } |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @param string $cacheKey |
|
139 | + * @param string|int $ttl |
|
140 | + * @param string $namespace |
|
141 | + * @return void |
|
142 | + */ |
|
143 | + public function renewCache(string $cacheKey, string|int $ttl, string $namespace = '') |
|
144 | + { |
|
145 | + $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
|
146 | + $dump = $this->getDump($cacheFullKey); |
|
147 | + |
|
148 | + if (!$dump) { |
|
149 | + $this->setMessage("Cache Key: {$cacheKey} not found.", false); |
|
150 | + $this->logger->warning("{$this->getMessage()} from Redis driver."); |
|
151 | + return; |
|
152 | + } |
|
153 | + |
|
154 | + $this->clearCache($cacheFullKey); |
|
155 | + |
|
156 | + if ($this->restoreKey($cacheFullKey, $ttl, $dump)) { |
|
157 | + $this->setMessage("Cache Key: {$cacheKey} renewed successfully.", true); |
|
158 | + $this->logger->debug("{$this->getMessage()} from Redis driver."); |
|
159 | + } else { |
|
160 | + $this->setMessage("Failed to renew cache key: {$cacheKey}.", false); |
|
161 | + $this->logger->error("{$this->getMessage()} from Redis driver."); |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * @param string $cacheKey |
|
168 | + * @param mixed $cacheData |
|
169 | + * @param string $namespace |
|
170 | + * @return void |
|
171 | + */ |
|
172 | + public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = '') |
|
173 | + { |
|
174 | + $cacheFullKey = $this->buildKey($cacheKey, $namespace); |
|
175 | + $existingData = $this->getCache($cacheFullKey); |
|
176 | + |
|
177 | + $mergedCacheData = CacheRedisHelper::arrayIdentifier($existingData, $cacheData); |
|
178 | + |
|
179 | + $serializedData = CacheRedisHelper::serialize($mergedCacheData); |
|
180 | + |
|
181 | + if ($this->redis->set($cacheFullKey, $serializedData)) { |
|
182 | + $this->setMessage("Cache appended successfully", true); |
|
183 | + } else { |
|
184 | + $this->setMessage("Something went wrong. Please, try again.", false); |
|
185 | + } |
|
186 | 186 | |
187 | 187 | |
188 | - $this->logger->debug("{$this->getMessage()} from redis driver."); |
|
189 | - } |
|
188 | + $this->logger->debug("{$this->getMessage()} from redis driver."); |
|
189 | + } |
|
190 | 190 | |
191 | 191 | |
192 | - /** |
|
193 | - * @param array $items |
|
194 | - * @param string $namespace |
|
195 | - * @param int $batchSize |
|
196 | - * @return bool |
|
197 | - */ |
|
198 | - public function putMany(array $items, string $namespace = '', int $batchSize = 100) |
|
199 | - { |
|
200 | - $processedCount = 0; |
|
201 | - $itemCount = count($items); |
|
192 | + /** |
|
193 | + * @param array $items |
|
194 | + * @param string $namespace |
|
195 | + * @param int $batchSize |
|
196 | + * @return bool |
|
197 | + */ |
|
198 | + public function putMany(array $items, string $namespace = '', int $batchSize = 100) |
|
199 | + { |
|
200 | + $processedCount = 0; |
|
201 | + $itemCount = count($items); |
|
202 | 202 | |
203 | - while($processedCount < $itemCount) |
|
204 | - { |
|
203 | + while($processedCount < $itemCount) |
|
204 | + { |
|
205 | 205 | |
206 | 206 | $batchItems = array_slice($items, $processedCount, $batchSize); |
207 | 207 | $this->processBatchItems($batchItems, $namespace); |
208 | 208 | $processedCount += count($batchItems); |
209 | - } |
|
209 | + } |
|
210 | 210 | |
211 | - } |
|
211 | + } |
|
212 | 212 | |
213 | - /** |
|
214 | - * @return void |
|
215 | - */ |
|
216 | - public function flushCache() |
|
217 | - { |
|
213 | + /** |
|
214 | + * @return void |
|
215 | + */ |
|
216 | + public function flushCache() |
|
217 | + { |
|
218 | 218 | |
219 | 219 | if($this->redis->flushall()) { |
220 | 220 | $this->setMessage("Cache flushed successfully", true); |
@@ -223,7 +223,7 @@ discard block |
||
223 | 223 | } |
224 | 224 | |
225 | 225 | $this->logger->debug("{$this->getMessage()} from redis driver."); |
226 | - } |
|
226 | + } |
|
227 | 227 | |
228 | 228 | /** |
229 | 229 | * @return string |
@@ -241,17 +241,17 @@ discard block |
||
241 | 241 | return $this->success; |
242 | 242 | } |
243 | 243 | |
244 | - /** |
|
245 | - * @param string $key |
|
246 | - * @param string $namespace |
|
247 | - * @return string |
|
248 | - */ |
|
249 | - private function buildKey(string $key, string $namespace) |
|
250 | - { |
|
244 | + /** |
|
245 | + * @param string $key |
|
246 | + * @param string $namespace |
|
247 | + * @return string |
|
248 | + */ |
|
249 | + private function buildKey(string $key, string $namespace) |
|
250 | + { |
|
251 | 251 | return $this->namespace . ($namespace ? $namespace . ':' : '') . $key; |
252 | - } |
|
252 | + } |
|
253 | 253 | |
254 | - /** |
|
254 | + /** |
|
255 | 255 | * @param string $message |
256 | 256 | * @param boolean $success |
257 | 257 | * @return void |
@@ -263,10 +263,10 @@ discard block |
||
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
266 | - * @param array $batchItems |
|
267 | - * @param string $namespace |
|
268 | - * @return void |
|
269 | - */ |
|
266 | + * @param array $batchItems |
|
267 | + * @param string $namespace |
|
268 | + * @return void |
|
269 | + */ |
|
270 | 270 | private function processBatchItems(array $batchItems, string $namespace) |
271 | 271 | { |
272 | 272 | foreach($batchItems as $item) { |
@@ -278,29 +278,29 @@ discard block |
||
278 | 278 | } |
279 | 279 | } |
280 | 280 | |
281 | - /** |
|
282 | - * @param string $fullKey |
|
283 | - * @return string|null |
|
284 | - */ |
|
285 | - private function getDump(string $fullKey) |
|
286 | - { |
|
287 | - return $this->redis->dump($fullKey); |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - /** |
|
292 | - * @param string $fullKey |
|
293 | - * @param string|int $ttl |
|
294 | - * @param mixed $dump |
|
295 | - * @return bool |
|
296 | - */ |
|
297 | - private function restoreKey(string $fullKey, string|int $ttl, mixed $dump) |
|
298 | - { |
|
299 | - try { |
|
300 | - $this->redis->restore($fullKey, $ttl * 1000, $dump, 'REPLACE'); |
|
301 | - return true; |
|
302 | - } catch (Exception $e) { |
|
303 | - throw CacheRedisException::create($e->getMessage()); |
|
304 | - } |
|
305 | - } |
|
281 | + /** |
|
282 | + * @param string $fullKey |
|
283 | + * @return string|null |
|
284 | + */ |
|
285 | + private function getDump(string $fullKey) |
|
286 | + { |
|
287 | + return $this->redis->dump($fullKey); |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + /** |
|
292 | + * @param string $fullKey |
|
293 | + * @param string|int $ttl |
|
294 | + * @param mixed $dump |
|
295 | + * @return bool |
|
296 | + */ |
|
297 | + private function restoreKey(string $fullKey, string|int $ttl, mixed $dump) |
|
298 | + { |
|
299 | + try { |
|
300 | + $this->redis->restore($fullKey, $ttl * 1000, $dump, 'REPLACE'); |
|
301 | + return true; |
|
302 | + } catch (Exception $e) { |
|
303 | + throw CacheRedisException::create($e->getMessage()); |
|
304 | + } |
|
305 | + } |
|
306 | 306 | } |
@@ -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']; |
@@ -46,13 +46,13 @@ |
||
46 | 46 | private string $lastFlushTimeFile; |
47 | 47 | |
48 | 48 | /** |
49 | - * @var CacheLogger |
|
50 | - */ |
|
49 | + * @var CacheLogger |
|
50 | + */ |
|
51 | 51 | private $logger = null; |
52 | 52 | |
53 | 53 | /** |
54 | - * @var FileCacheManager |
|
55 | - */ |
|
54 | + * @var FileCacheManager |
|
55 | + */ |
|
56 | 56 | private FileCacheManager $fileManager; |
57 | 57 | |
58 | 58 | public function __construct(array $options = []) |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | * @param string|int $ttl |
73 | 73 | * @return string|null |
74 | 74 | */ |
75 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
75 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
76 | 76 | { |
77 | 77 | |
78 | 78 | $ttl = CacheFileHelper::ttl($ttl, $this->defaultTTL); |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * @param string|int $ttl |
98 | 98 | * @return void |
99 | 99 | */ |
100 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) |
|
100 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) |
|
101 | 101 | { |
102 | 102 | $cacheFile = $this->buildCacheFilePath($cacheKey, $namespace); |
103 | 103 | $data = $this->fileManager->serialize($cacheData); |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * @param string $namespace |
172 | 172 | * @return void |
173 | 173 | */ |
174 | - public function renewCache(string $cacheKey, string|int $ttl, string $namespace = '') |
|
174 | + public function renewCache(string $cacheKey, string | int $ttl, string $namespace = '') |
|
175 | 175 | { |
176 | 176 | $cacheData = $this->getCache($cacheKey, $namespace); |
177 | 177 | if ($cacheData) { |
@@ -15,9 +15,9 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | /** |
18 | - * @param array|null $database |
|
19 | - * @return PDO|null |
|
20 | - */ |
|
18 | + * @param array|null $database |
|
19 | + * @return PDO|null |
|
20 | + */ |
|
21 | 21 | public static function createConnection(array $database = null) |
22 | 22 | { |
23 | 23 | $dbConf = $database ?? CACHEER_DATABASE_CONFIG[Connect::getConnection()]; |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | |
19 | 19 | |
20 | 20 | /** |
21 | - * @param array|null $database |
|
22 | - * @return PDO|null |
|
23 | - */ |
|
21 | + * @param array|null $database |
|
22 | + * @return PDO|null |
|
23 | + */ |
|
24 | 24 | public static function getInstance(array $database = null) |
25 | 25 | { |
26 | 26 | $pdo = ConnectionFactory::createConnection($database); |
@@ -31,9 +31,9 @@ discard block |
||
31 | 31 | } |
32 | 32 | |
33 | 33 | /** |
34 | - * @param string $connection |
|
35 | - * @return void |
|
36 | - */ |
|
34 | + * @param string $connection |
|
35 | + * @return void |
|
36 | + */ |
|
37 | 37 | public static function setConnection(string $connection) |
38 | 38 | { |
39 | 39 | $drivers = ['mysql', 'sqlite', 'pgsql']; |
@@ -44,16 +44,16 @@ discard block |
||
44 | 44 | } |
45 | 45 | |
46 | 46 | /** |
47 | - * @return string |
|
48 | - */ |
|
47 | + * @return string |
|
48 | + */ |
|
49 | 49 | public static function getConnection() |
50 | 50 | { |
51 | 51 | return self::$connection; |
52 | 52 | } |
53 | 53 | |
54 | 54 | /** |
55 | - * @return PDOException|null |
|
56 | - */ |
|
55 | + * @return PDOException|null |
|
56 | + */ |
|
57 | 57 | public static function getError() |
58 | 58 | { |
59 | 59 | return self::$error; |
@@ -13,8 +13,8 @@ |
||
13 | 13 | class MigrationManager |
14 | 14 | { |
15 | 15 | /** |
16 | - * @return void |
|
17 | - */ |
|
16 | + * @return void |
|
17 | + */ |
|
18 | 18 | public static function migrate(PDO $connection) |
19 | 19 | { |
20 | 20 | $driver = $connection->getAttribute(PDO::ATTR_DRIVER_NAME); |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * @param string|int $ttl |
55 | 55 | * @return CacheDataFormatter|mixed |
56 | 56 | */ |
57 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
57 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
58 | 58 | { |
59 | 59 | $cacheData = $this->cacheStore->getCache($cacheKey, $namespace, $ttl); |
60 | 60 | $this->setMessage($this->cacheStore->getMessage(), $this->cacheStore->isSuccess()); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @param string|int $ttl |
69 | 69 | * @return void |
70 | 70 | */ |
71 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600) |
|
71 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600) |
|
72 | 72 | { |
73 | 73 | $this->cacheStore->putCache($cacheKey, $cacheData, $namespace, $ttl); |
74 | 74 | $this->setMessage($this->cacheStore->getMessage(), $this->cacheStore->isSuccess()); |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | * @param string $namespace |
114 | 114 | * @return mixed |
115 | 115 | */ |
116 | - public function renewCache(string $cacheKey, string|int $ttl = 3600, string $namespace = '') |
|
116 | + public function renewCache(string $cacheKey, string | int $ttl = 3600, string $namespace = '') |
|
117 | 117 | { |
118 | 118 | $renewedCache = $this->cacheStore->renewCache($cacheKey, $ttl, $namespace); |
119 | 119 |
@@ -8,34 +8,34 @@ |
||
8 | 8 | { |
9 | 9 | |
10 | 10 | |
11 | - /** @param string $before */ |
|
12 | - private static string $before = "<Redis Cache Store Exception>"; |
|
11 | + /** @param string $before */ |
|
12 | + private static string $before = "<Redis Cache Store Exception>"; |
|
13 | 13 | |
14 | 14 | |
15 | 15 | /** |
16 | - * @return void |
|
17 | - */ |
|
18 | - public static function create(string $message = "", int $code = 0, ?Exception $previous = null, array $details = []) |
|
19 | - { |
|
16 | + * @return void |
|
17 | + */ |
|
18 | + public static function create(string $message = "", int $code = 0, ?Exception $previous = null, array $details = []) |
|
19 | + { |
|
20 | 20 | return new self(self::getBefore() . ": " .$message, $code, $previous, $details); |
21 | - } |
|
21 | + } |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * @return string |
|
26 | - */ |
|
27 | - public static function getBefore() |
|
28 | - { |
|
24 | + /** |
|
25 | + * @return string |
|
26 | + */ |
|
27 | + public static function getBefore() |
|
28 | + { |
|
29 | 29 | return self::$before; |
30 | - } |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * @return void |
|
34 | - */ |
|
35 | - public static function setBefore(string $text) |
|
36 | - { |
|
32 | + /** |
|
33 | + * @return void |
|
34 | + */ |
|
35 | + public static function setBefore(string $text) |
|
36 | + { |
|
37 | 37 | self::$before = $text; |
38 | - } |
|
38 | + } |
|
39 | 39 | |
40 | 40 | } |
41 | 41 |
@@ -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 |