@@ -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); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @param int|string $ttl |
87 | 87 | * @return bool |
88 | 88 | */ |
89 | - public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
|
89 | + public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600) |
|
90 | 90 | { |
91 | 91 | return $this->mutator->add($cacheKey, $cacheData, $namespace, $ttl); |
92 | 92 | } |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * @param string|int $ttl |
183 | 183 | * @return CacheDataFormatter|mixed |
184 | 184 | */ |
185 | - public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
|
185 | + public function getCache(string $cacheKey, string $namespace = '', string | int $ttl = 3600) |
|
186 | 186 | { |
187 | 187 | return $this->retriever->getCache($cacheKey, $namespace, $ttl); |
188 | 188 | } |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | * @param string|int $ttl |
196 | 196 | * @return CacheDataFormatter|mixed |
197 | 197 | */ |
198 | - public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600) |
|
198 | + public function getMany(array $cacheKeys, string $namespace = '', string | int $ttl = 3600) |
|
199 | 199 | { |
200 | 200 | return $this->retriever->getMany($cacheKeys, $namespace, $ttl); |
201 | 201 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | * @param string|int $ttl |
245 | 245 | * @return void |
246 | 246 | */ |
247 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600): void |
|
247 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string | int $ttl = 3600): void |
|
248 | 248 | { |
249 | 249 | $this->mutator->putCache($cacheKey, $cacheData, $namespace, $ttl); |
250 | 250 | } |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * @param string $namespace |
271 | 271 | * @return void |
272 | 272 | */ |
273 | - public function renewCache(string $cacheKey, string|int $ttl = 3600, string $namespace = ''): void |
|
273 | + public function renewCache(string $cacheKey, string | int $ttl = 3600, string $namespace = ''): void |
|
274 | 274 | { |
275 | 275 | $this->mutator->renewCache($cacheKey, $ttl, $namespace); |
276 | 276 | } |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @param Closure $callback |
284 | 284 | * @return mixed |
285 | 285 | */ |
286 | - public function remember(string $cacheKey, int|string $ttl, Closure $callback) |
|
286 | + public function remember(string $cacheKey, int | string $ttl, Closure $callback) |
|
287 | 287 | { |
288 | 288 | return $this->retriever->remember($cacheKey, $ttl, $callback); |
289 | 289 | } |
@@ -24,57 +24,57 @@ discard block |
||
24 | 24 | final class Cacheer implements CacheerInterface |
25 | 25 | { |
26 | 26 | /** |
27 | - * @var string |
|
28 | - */ |
|
27 | + * @var string |
|
28 | + */ |
|
29 | 29 | private string $message; |
30 | 30 | |
31 | 31 | /** |
32 | - * @var boolean |
|
33 | - */ |
|
32 | + * @var boolean |
|
33 | + */ |
|
34 | 34 | private bool $success; |
35 | 35 | |
36 | 36 | /** |
37 | - * @var boolean |
|
38 | - */ |
|
37 | + * @var boolean |
|
38 | + */ |
|
39 | 39 | private bool $formatted = false; |
40 | 40 | |
41 | 41 | /** |
42 | - * @var bool |
|
43 | - */ |
|
42 | + * @var bool |
|
43 | + */ |
|
44 | 44 | private bool $compression = false; |
45 | 45 | |
46 | 46 | /** |
47 | - * @var string|null |
|
48 | - */ |
|
47 | + * @var string|null |
|
48 | + */ |
|
49 | 49 | private ?string $encryptionKey = null; |
50 | 50 | |
51 | 51 | /** |
52 | - * @var FileCacheStore|DatabaseCacheStore|RedisCacheStore|ArrayCacheStore |
|
53 | - */ |
|
52 | + * @var FileCacheStore|DatabaseCacheStore|RedisCacheStore|ArrayCacheStore |
|
53 | + */ |
|
54 | 54 | public $cacheStore; |
55 | 55 | |
56 | 56 | /** |
57 | - * @var array |
|
58 | - */ |
|
57 | + * @var array |
|
58 | + */ |
|
59 | 59 | public array $options = []; |
60 | 60 | |
61 | 61 | /** |
62 | - * @var CacheRetriever |
|
63 | - */ |
|
62 | + * @var CacheRetriever |
|
63 | + */ |
|
64 | 64 | private CacheRetriever $retriever; |
65 | 65 | |
66 | 66 | /** |
67 | - * @var CacheMutator |
|
68 | - */ |
|
67 | + * @var CacheMutator |
|
68 | + */ |
|
69 | 69 | private CacheMutator $mutator; |
70 | 70 | |
71 | 71 | /** |
72 | - * Cacheer constructor. |
|
73 | - * |
|
74 | - * @param array $options |
|
75 | - * @param bool $formatted |
|
76 | - * @throws RuntimeException |
|
77 | - */ |
|
72 | + * Cacheer constructor. |
|
73 | + * |
|
74 | + * @param array $options |
|
75 | + * @param bool $formatted |
|
76 | + * @throws RuntimeException |
|
77 | + */ |
|
78 | 78 | public function __construct(array $options = [], $formatted = false) |
79 | 79 | { |
80 | 80 | $this->formatted = $formatted; |
@@ -85,255 +85,255 @@ discard block |
||
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
88 | - * Adds data to the cache if it does not already exist. |
|
89 | - * |
|
90 | - * @param string $cacheKey |
|
91 | - * @param mixed $cacheData |
|
92 | - * @param string $namespace |
|
93 | - * @param int|string $ttl |
|
94 | - * @return bool |
|
95 | - */ |
|
88 | + * Adds data to the cache if it does not already exist. |
|
89 | + * |
|
90 | + * @param string $cacheKey |
|
91 | + * @param mixed $cacheData |
|
92 | + * @param string $namespace |
|
93 | + * @param int|string $ttl |
|
94 | + * @return bool |
|
95 | + */ |
|
96 | 96 | public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
97 | 97 | { |
98 | 98 | return $this->mutator->add($cacheKey, $cacheData, $namespace, $ttl); |
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
102 | - * Appends data to an existing cache item. |
|
103 | - * |
|
104 | - * @param string $cacheKey |
|
105 | - * @param mixed $cacheData |
|
106 | - * @param string $namespace |
|
107 | - * @return void |
|
108 | - */ |
|
102 | + * Appends data to an existing cache item. |
|
103 | + * |
|
104 | + * @param string $cacheKey |
|
105 | + * @param mixed $cacheData |
|
106 | + * @param string $namespace |
|
107 | + * @return void |
|
108 | + */ |
|
109 | 109 | public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = ''): void |
110 | 110 | { |
111 | 111 | $this->mutator->appendCache($cacheKey, $cacheData, $namespace); |
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | - * Clears a specific cache item. |
|
116 | - * |
|
117 | - * @param string $cacheKey |
|
118 | - * @param string $namespace |
|
119 | - * @return void |
|
120 | - */ |
|
115 | + * Clears a specific cache item. |
|
116 | + * |
|
117 | + * @param string $cacheKey |
|
118 | + * @param string $namespace |
|
119 | + * @return void |
|
120 | + */ |
|
121 | 121 | public function clearCache(string $cacheKey, string $namespace = ''): void |
122 | 122 | { |
123 | 123 | $this->mutator->clearCache($cacheKey, $namespace); |
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
127 | - * Decrements a cache item by a specified amount. |
|
128 | - * |
|
129 | - * @param string $cacheKey |
|
130 | - * @param int $amount |
|
131 | - * @param string $namespace |
|
132 | - * @return bool |
|
133 | - */ |
|
127 | + * Decrements a cache item by a specified amount. |
|
128 | + * |
|
129 | + * @param string $cacheKey |
|
130 | + * @param int $amount |
|
131 | + * @param string $namespace |
|
132 | + * @return bool |
|
133 | + */ |
|
134 | 134 | public function decrement(string $cacheKey, int $amount = 1, string $namespace = '') |
135 | 135 | { |
136 | 136 | return $this->mutator->decrement($cacheKey, $amount, $namespace); |
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
140 | - * Store data in the cache permanently. |
|
141 | - * |
|
142 | - * @param string $cacheKey |
|
143 | - * @param mixed $cacheData |
|
144 | - * @return void |
|
145 | - */ |
|
140 | + * Store data in the cache permanently. |
|
141 | + * |
|
142 | + * @param string $cacheKey |
|
143 | + * @param mixed $cacheData |
|
144 | + * @return void |
|
145 | + */ |
|
146 | 146 | public function forever(string $cacheKey, mixed $cacheData): void |
147 | 147 | { |
148 | 148 | $this->mutator->forever($cacheKey, $cacheData); |
149 | 149 | } |
150 | 150 | |
151 | 151 | /** |
152 | - * Flushes all cache items. |
|
153 | - * |
|
154 | - * @return void |
|
155 | - */ |
|
152 | + * Flushes all cache items. |
|
153 | + * |
|
154 | + * @return void |
|
155 | + */ |
|
156 | 156 | public function flushCache(): void |
157 | 157 | { |
158 | 158 | $this->mutator->flushCache(); |
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
162 | - * Retrieves a cache item and deletes it from the cache. |
|
163 | - * |
|
164 | - * @param string $cacheKey |
|
165 | - * @param string $namespace |
|
166 | - * @return mixed |
|
167 | - */ |
|
162 | + * Retrieves a cache item and deletes it from the cache. |
|
163 | + * |
|
164 | + * @param string $cacheKey |
|
165 | + * @param string $namespace |
|
166 | + * @return mixed |
|
167 | + */ |
|
168 | 168 | public function getAndForget(string $cacheKey, string $namespace = '') |
169 | 169 | { |
170 | 170 | return $this->retriever->getAndForget($cacheKey, $namespace); |
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
174 | - * Gets all items in a specific namespace. |
|
175 | - * |
|
176 | - * @param string $namespace |
|
177 | - * @return CacheDataFormatter|mixed |
|
178 | - */ |
|
174 | + * Gets all items in a specific namespace. |
|
175 | + * |
|
176 | + * @param string $namespace |
|
177 | + * @return CacheDataFormatter|mixed |
|
178 | + */ |
|
179 | 179 | public function getAll(string $namespace = '') |
180 | 180 | { |
181 | 181 | return $this->retriever->getAll($namespace); |
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
185 | - * Retrieves a single cache item. |
|
186 | - * |
|
187 | - * @param string $cacheKey |
|
188 | - * @param string $namespace |
|
189 | - * @param string|int $ttl |
|
190 | - * @return CacheDataFormatter|mixed |
|
191 | - */ |
|
185 | + * Retrieves a single cache item. |
|
186 | + * |
|
187 | + * @param string $cacheKey |
|
188 | + * @param string $namespace |
|
189 | + * @param string|int $ttl |
|
190 | + * @return CacheDataFormatter|mixed |
|
191 | + */ |
|
192 | 192 | public function getCache(string $cacheKey, string $namespace = '', string|int $ttl = 3600) |
193 | 193 | { |
194 | 194 | return $this->retriever->getCache($cacheKey, $namespace, $ttl); |
195 | 195 | } |
196 | 196 | |
197 | 197 | /** |
198 | - * Retrieves multiple cache items by their keys. |
|
199 | - * |
|
200 | - * @param array $cacheKeys |
|
201 | - * @param string $namespace |
|
202 | - * @param string|int $ttl |
|
203 | - * @return CacheDataFormatter|mixed |
|
204 | - */ |
|
198 | + * Retrieves multiple cache items by their keys. |
|
199 | + * |
|
200 | + * @param array $cacheKeys |
|
201 | + * @param string $namespace |
|
202 | + * @param string|int $ttl |
|
203 | + * @return CacheDataFormatter|mixed |
|
204 | + */ |
|
205 | 205 | public function getMany(array $cacheKeys, string $namespace = '', string|int $ttl = 3600) |
206 | 206 | { |
207 | 207 | return $this->retriever->getMany($cacheKeys, $namespace, $ttl); |
208 | 208 | } |
209 | 209 | |
210 | 210 | /** |
211 | - * Checks if a cache item exists. |
|
212 | - * |
|
213 | - * @param string $cacheKey |
|
214 | - * @param string $namespace |
|
215 | - * @return void |
|
216 | - */ |
|
211 | + * Checks if a cache item exists. |
|
212 | + * |
|
213 | + * @param string $cacheKey |
|
214 | + * @param string $namespace |
|
215 | + * @return void |
|
216 | + */ |
|
217 | 217 | public function has(string $cacheKey, string $namespace = ''): void |
218 | 218 | { |
219 | 219 | $this->retriever->has($cacheKey, $namespace); |
220 | 220 | } |
221 | 221 | |
222 | 222 | /** |
223 | - * Increments a cache item by a specified amount. |
|
224 | - * |
|
225 | - * @param string $cacheKey |
|
226 | - * @param int $amount |
|
227 | - * @param string $namespace |
|
228 | - * @return bool |
|
229 | - */ |
|
223 | + * Increments a cache item by a specified amount. |
|
224 | + * |
|
225 | + * @param string $cacheKey |
|
226 | + * @param int $amount |
|
227 | + * @param string $namespace |
|
228 | + * @return bool |
|
229 | + */ |
|
230 | 230 | public function increment(string $cacheKey, int $amount = 1, string $namespace = '') |
231 | 231 | { |
232 | 232 | return $this->mutator->increment($cacheKey, $amount, $namespace); |
233 | 233 | } |
234 | 234 | |
235 | 235 | /** |
236 | - * Checks if the last operation was successful. |
|
237 | - * |
|
238 | - * @return boolean |
|
239 | - */ |
|
236 | + * Checks if the last operation was successful. |
|
237 | + * |
|
238 | + * @return boolean |
|
239 | + */ |
|
240 | 240 | public function isSuccess() |
241 | 241 | { |
242 | 242 | return $this->success; |
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
246 | - * Stores an item in the cache with a specific TTL. |
|
247 | - * |
|
248 | - * @param string $cacheKey |
|
249 | - * @param mixed $cacheData |
|
250 | - * @param string $namespace |
|
251 | - * @param string|int $ttl |
|
252 | - * @return void |
|
253 | - */ |
|
246 | + * Stores an item in the cache with a specific TTL. |
|
247 | + * |
|
248 | + * @param string $cacheKey |
|
249 | + * @param mixed $cacheData |
|
250 | + * @param string $namespace |
|
251 | + * @param string|int $ttl |
|
252 | + * @return void |
|
253 | + */ |
|
254 | 254 | public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', string|int $ttl = 3600): void |
255 | 255 | { |
256 | 256 | $this->mutator->putCache($cacheKey, $cacheData, $namespace, $ttl); |
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
260 | - * Stores multiple items in the cache. |
|
261 | - * |
|
262 | - * @param array $items |
|
263 | - * @param string $namespace |
|
264 | - * @param integer $batchSize |
|
265 | - * @return void |
|
266 | - */ |
|
260 | + * Stores multiple items in the cache. |
|
261 | + * |
|
262 | + * @param array $items |
|
263 | + * @param string $namespace |
|
264 | + * @param integer $batchSize |
|
265 | + * @return void |
|
266 | + */ |
|
267 | 267 | public function putMany(array $items, string $namespace = '', int $batchSize = 100): void |
268 | 268 | { |
269 | 269 | $this->mutator->putMany($items, $namespace, $batchSize); |
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
273 | - * Renews the cache for a specific key with a new TTL. |
|
274 | - * |
|
275 | - * @param string $cacheKey |
|
276 | - * @param string|int $ttl |
|
277 | - * @param string $namespace |
|
278 | - * @return void |
|
279 | - */ |
|
273 | + * Renews the cache for a specific key with a new TTL. |
|
274 | + * |
|
275 | + * @param string $cacheKey |
|
276 | + * @param string|int $ttl |
|
277 | + * @param string $namespace |
|
278 | + * @return void |
|
279 | + */ |
|
280 | 280 | public function renewCache(string $cacheKey, string|int $ttl = 3600, string $namespace = ''): void |
281 | 281 | { |
282 | 282 | $this->mutator->renewCache($cacheKey, $ttl, $namespace); |
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
286 | - * Retrieves a cache item or executes a callback to store it if not found. |
|
287 | - * |
|
288 | - * @param string $cacheKey |
|
289 | - * @param int|string $ttl |
|
290 | - * @param Closure $callback |
|
291 | - * @return mixed |
|
292 | - */ |
|
286 | + * Retrieves a cache item or executes a callback to store it if not found. |
|
287 | + * |
|
288 | + * @param string $cacheKey |
|
289 | + * @param int|string $ttl |
|
290 | + * @param Closure $callback |
|
291 | + * @return mixed |
|
292 | + */ |
|
293 | 293 | public function remember(string $cacheKey, int|string $ttl, Closure $callback) |
294 | 294 | { |
295 | 295 | return $this->retriever->remember($cacheKey, $ttl, $callback); |
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
299 | - * Retrieves a cache item or executes a callback to store it permanently if not found. |
|
300 | - * |
|
301 | - * @param string $cacheKey |
|
302 | - * @param Closure $callback |
|
303 | - * @return mixed |
|
304 | - */ |
|
299 | + * Retrieves a cache item or executes a callback to store it permanently if not found. |
|
300 | + * |
|
301 | + * @param string $cacheKey |
|
302 | + * @param Closure $callback |
|
303 | + * @return mixed |
|
304 | + */ |
|
305 | 305 | public function rememberForever(string $cacheKey, Closure $callback) |
306 | 306 | { |
307 | 307 | return $this->retriever->rememberForever($cacheKey, $callback); |
308 | 308 | } |
309 | 309 | |
310 | 310 | /** |
311 | - * Returns a CacheConfig instance for configuration management. |
|
312 | - * |
|
313 | - * @return CacheConfig |
|
314 | - */ |
|
311 | + * Returns a CacheConfig instance for configuration management. |
|
312 | + * |
|
313 | + * @return CacheConfig |
|
314 | + */ |
|
315 | 315 | public function setConfig() |
316 | 316 | { |
317 | 317 | return new CacheConfig($this); |
318 | 318 | } |
319 | 319 | |
320 | 320 | /** |
321 | - * Sets the cache driver based on the configuration. |
|
322 | - * |
|
323 | - * @return CacheDriver |
|
324 | - */ |
|
321 | + * Sets the cache driver based on the configuration. |
|
322 | + * |
|
323 | + * @return CacheDriver |
|
324 | + */ |
|
325 | 325 | public function setDriver() |
326 | 326 | { |
327 | 327 | return new CacheDriver($this); |
328 | 328 | } |
329 | 329 | |
330 | 330 | /** |
331 | - * Sets a message for the cache operation. |
|
332 | - * |
|
333 | - * @param string $message |
|
334 | - * @param boolean $success |
|
335 | - * @return void |
|
336 | - */ |
|
331 | + * Sets a message for the cache operation. |
|
332 | + * |
|
333 | + * @param string $message |
|
334 | + * @param boolean $success |
|
335 | + * @return void |
|
336 | + */ |
|
337 | 337 | private function setMessage(string $message, bool $success) |
338 | 338 | { |
339 | 339 | $this->message = $message; |
@@ -341,10 +341,10 @@ discard block |
||
341 | 341 | } |
342 | 342 | |
343 | 343 | /** |
344 | - * Retrieves the message from the last operation. |
|
345 | - * |
|
346 | - * @return string |
|
347 | - */ |
|
344 | + * Retrieves the message from the last operation. |
|
345 | + * |
|
346 | + * @return string |
|
347 | + */ |
|
348 | 348 | public function getMessage() |
349 | 349 | { |
350 | 350 | return $this->message; |
@@ -376,32 +376,32 @@ discard block |
||
376 | 376 | } |
377 | 377 | |
378 | 378 | /** |
379 | - * Enables or disables the formatter for cache data. |
|
380 | - * |
|
381 | - * @return void |
|
382 | - */ |
|
379 | + * Enables or disables the formatter for cache data. |
|
380 | + * |
|
381 | + * @return void |
|
382 | + */ |
|
383 | 383 | public function useFormatter() |
384 | 384 | { |
385 | 385 | $this->formatted = !$this->formatted; |
386 | 386 | } |
387 | 387 | |
388 | 388 | /** |
389 | - * Validates the options provided for the Cacheer instance. |
|
390 | - * |
|
391 | - * @param array $options |
|
392 | - * @return void |
|
393 | - */ |
|
389 | + * Validates the options provided for the Cacheer instance. |
|
390 | + * |
|
391 | + * @param array $options |
|
392 | + * @return void |
|
393 | + */ |
|
394 | 394 | private function validateOptions(array $options) |
395 | 395 | { |
396 | 396 | $this->options = $options; |
397 | 397 | } |
398 | 398 | |
399 | 399 | /** |
400 | - * Enable or disable data compression |
|
401 | - * |
|
402 | - * @param bool $status |
|
403 | - * @return $this |
|
404 | - */ |
|
400 | + * Enable or disable data compression |
|
401 | + * |
|
402 | + * @param bool $status |
|
403 | + * @return $this |
|
404 | + */ |
|
405 | 405 | public function useCompression(bool $status = true) |
406 | 406 | { |
407 | 407 | $this->compression = $status; |
@@ -409,11 +409,11 @@ discard block |
||
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
412 | - * Enable encryption for cached data |
|
413 | - * |
|
414 | - * @param string $key |
|
415 | - * @return $this |
|
416 | - */ |
|
412 | + * Enable encryption for cached data |
|
413 | + * |
|
414 | + * @param string $key |
|
415 | + * @return $this |
|
416 | + */ |
|
417 | 417 | public function useEncryption(string $key) |
418 | 418 | { |
419 | 419 | $this->encryptionKey = $key; |
@@ -15,28 +15,28 @@ discard block |
||
15 | 15 | class CacheRetriever |
16 | 16 | { |
17 | 17 | /** |
18 | - * @var Cacheer |
|
19 | - */ |
|
18 | + * @var Cacheer |
|
19 | + */ |
|
20 | 20 | private Cacheer $cacheer; |
21 | 21 | |
22 | 22 | /** |
23 | - * CacheRetriever constructor. |
|
24 | - * |
|
25 | - * @param Cacheer $cacheer |
|
26 | - */ |
|
23 | + * CacheRetriever constructor. |
|
24 | + * |
|
25 | + * @param Cacheer $cacheer |
|
26 | + */ |
|
27 | 27 | public function __construct(Cacheer $cacheer) |
28 | 28 | { |
29 | 29 | $this->cacheer = $cacheer; |
30 | 30 | } |
31 | 31 | |
32 | 32 | /** |
33 | - * Retrieves a cache item by its key. |
|
34 | - * |
|
35 | - * @param string $cacheKey |
|
36 | - * @param string $namespace |
|
37 | - * @param int|string $ttl |
|
38 | - * @return mixed |
|
39 | - */ |
|
33 | + * Retrieves a cache item by its key. |
|
34 | + * |
|
35 | + * @param string $cacheKey |
|
36 | + * @param string $namespace |
|
37 | + * @param int|string $ttl |
|
38 | + * @return mixed |
|
39 | + */ |
|
40 | 40 | public function getCache(string $cacheKey, string $namespace = '', int|string $ttl = 3600) |
41 | 41 | { |
42 | 42 | $cacheData = $this->cacheer->cacheStore->getCache($cacheKey, $namespace, $ttl); |
@@ -50,13 +50,13 @@ discard block |
||
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
53 | - * Retrieves multiple cache items by their keys. |
|
54 | - * |
|
55 | - * @param array $cacheKeys |
|
56 | - * @param string $namespace |
|
57 | - * @param int|string $ttl |
|
58 | - * @return array|CacheDataFormatter |
|
59 | - */ |
|
53 | + * Retrieves multiple cache items by their keys. |
|
54 | + * |
|
55 | + * @param array $cacheKeys |
|
56 | + * @param string $namespace |
|
57 | + * @param int|string $ttl |
|
58 | + * @return array|CacheDataFormatter |
|
59 | + */ |
|
60 | 60 | public function getMany(array $cacheKeys, string $namespace = '', int|string $ttl = 3600) |
61 | 61 | { |
62 | 62 | $cachedData = $this->cacheer->cacheStore->getMany($cacheKeys, $namespace, $ttl); |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
75 | - * Retrieves all cache items in a namespace. |
|
76 | - * |
|
77 | - * @param string $namespace |
|
78 | - * @return CacheDataFormatter|mixed |
|
79 | - */ |
|
75 | + * Retrieves all cache items in a namespace. |
|
76 | + * |
|
77 | + * @param string $namespace |
|
78 | + * @return CacheDataFormatter|mixed |
|
79 | + */ |
|
80 | 80 | public function getAll(string $namespace = '') |
81 | 81 | { |
82 | 82 | $cachedData = $this->cacheer->cacheStore->getAll($namespace); |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
95 | - * Retrieves a cache item, deletes it, and returns its data. |
|
96 | - * |
|
97 | - * @param string $cacheKey |
|
98 | - * @param string $namespace |
|
99 | - * @return mixed|null |
|
100 | - */ |
|
95 | + * Retrieves a cache item, deletes it, and returns its data. |
|
96 | + * |
|
97 | + * @param string $cacheKey |
|
98 | + * @param string $namespace |
|
99 | + * @return mixed|null |
|
100 | + */ |
|
101 | 101 | public function getAndForget(string $cacheKey, string $namespace = '') |
102 | 102 | { |
103 | 103 | $cachedData = $this->getCache($cacheKey, $namespace); |
@@ -112,13 +112,13 @@ discard block |
||
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | - * Retrieves a cache item, or executes a callback to store it if not found. |
|
116 | - * |
|
117 | - * @param string $cacheKey |
|
118 | - * @param int|string $ttl |
|
119 | - * @param Closure $callback |
|
120 | - * @return mixed |
|
121 | - */ |
|
115 | + * Retrieves a cache item, or executes a callback to store it if not found. |
|
116 | + * |
|
117 | + * @param string $cacheKey |
|
118 | + * @param int|string $ttl |
|
119 | + * @param Closure $callback |
|
120 | + * @return mixed |
|
121 | + */ |
|
122 | 122 | public function remember(string $cacheKey, int|string $ttl, Closure $callback) |
123 | 123 | { |
124 | 124 | $cachedData = $this->getCache($cacheKey, ttl: $ttl); |
@@ -133,24 +133,24 @@ discard block |
||
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
136 | - * Retrieves a cache item indefinitely, or executes a callback to store it if not found. |
|
137 | - * |
|
138 | - * @param string $cacheKey |
|
139 | - * @param Closure $callback |
|
140 | - * @return mixed |
|
141 | - */ |
|
136 | + * Retrieves a cache item indefinitely, or executes a callback to store it if not found. |
|
137 | + * |
|
138 | + * @param string $cacheKey |
|
139 | + * @param Closure $callback |
|
140 | + * @return mixed |
|
141 | + */ |
|
142 | 142 | public function rememberForever(string $cacheKey, Closure $callback) |
143 | 143 | { |
144 | 144 | return $this->remember($cacheKey, 31536000 * 1000, $callback); |
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
148 | - * Checks if a cache item exists. |
|
149 | - * |
|
150 | - * @param string $cacheKey |
|
151 | - * @param string $namespace |
|
152 | - * @return void |
|
153 | - */ |
|
148 | + * Checks if a cache item exists. |
|
149 | + * |
|
150 | + * @param string $cacheKey |
|
151 | + * @param string $namespace |
|
152 | + * @return void |
|
153 | + */ |
|
154 | 154 | public function has(string $cacheKey, string $namespace = '') |
155 | 155 | { |
156 | 156 | $this->cacheer->cacheStore->has($cacheKey, $namespace); |
@@ -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 |
@@ -13,29 +13,29 @@ discard block |
||
13 | 13 | class CacheMutator |
14 | 14 | { |
15 | 15 | /** |
16 | - * @var Cacheer |
|
17 | - */ |
|
16 | + * @var Cacheer |
|
17 | + */ |
|
18 | 18 | private Cacheer $cacheer; |
19 | 19 | |
20 | 20 | /** |
21 | - * CacheMutator constructor. |
|
22 | - * |
|
23 | - * @param Cacheer $cacheer |
|
24 | - */ |
|
21 | + * CacheMutator constructor. |
|
22 | + * |
|
23 | + * @param Cacheer $cacheer |
|
24 | + */ |
|
25 | 25 | public function __construct(Cacheer $cacheer) |
26 | 26 | { |
27 | 27 | $this->cacheer = $cacheer; |
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
31 | - * Adds a cache item if it does not already exist. |
|
32 | - * |
|
33 | - * @param string $cacheKey |
|
34 | - * @param mixed $cacheData |
|
35 | - * @param string $namespace |
|
36 | - * @param int|string $ttl |
|
37 | - * @return bool |
|
38 | - */ |
|
31 | + * Adds a cache item if it does not already exist. |
|
32 | + * |
|
33 | + * @param string $cacheKey |
|
34 | + * @param mixed $cacheData |
|
35 | + * @param string $namespace |
|
36 | + * @param int|string $ttl |
|
37 | + * @return bool |
|
38 | + */ |
|
39 | 39 | public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
40 | 40 | { |
41 | 41 | if (!empty($this->cacheer->getCache($cacheKey, $namespace))) { |
@@ -49,13 +49,13 @@ discard block |
||
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | - * Appends data to an existing cache item. |
|
53 | - * |
|
54 | - * @param string $cacheKey |
|
55 | - * @param mixed $cacheData |
|
56 | - * @param string $namespace |
|
57 | - * @return void |
|
58 | - */ |
|
52 | + * Appends data to an existing cache item. |
|
53 | + * |
|
54 | + * @param string $cacheKey |
|
55 | + * @param mixed $cacheData |
|
56 | + * @param string $namespace |
|
57 | + * @return void |
|
58 | + */ |
|
59 | 59 | public function appendCache(string $cacheKey, mixed $cacheData, string $namespace = '') |
60 | 60 | { |
61 | 61 | $this->cacheer->cacheStore->appendCache($cacheKey, $cacheData, $namespace); |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
66 | - * Clears a specific cache item. |
|
67 | - * |
|
68 | - * @param string $cacheKey |
|
69 | - * @param string $namespace |
|
70 | - * @return void |
|
71 | - */ |
|
66 | + * Clears a specific cache item. |
|
67 | + * |
|
68 | + * @param string $cacheKey |
|
69 | + * @param string $namespace |
|
70 | + * @return void |
|
71 | + */ |
|
72 | 72 | public function clearCache(string $cacheKey, string $namespace = '') |
73 | 73 | { |
74 | 74 | $this->cacheer->cacheStore->clearCache($cacheKey, $namespace); |
@@ -76,25 +76,25 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Decrements a numeric cache item by a specified amount. |
|
80 | - * |
|
81 | - * @param string $cacheKey |
|
82 | - * @param int $amount |
|
83 | - * @param string $namespace |
|
84 | - * @return bool |
|
85 | - */ |
|
79 | + * Decrements a numeric cache item by a specified amount. |
|
80 | + * |
|
81 | + * @param string $cacheKey |
|
82 | + * @param int $amount |
|
83 | + * @param string $namespace |
|
84 | + * @return bool |
|
85 | + */ |
|
86 | 86 | public function decrement(string $cacheKey, int $amount = 1, string $namespace = '') |
87 | 87 | { |
88 | 88 | return $this->increment($cacheKey, ($amount * -1), $namespace); |
89 | 89 | } |
90 | 90 | |
91 | 91 | /** |
92 | - * Checks if a cache item exists. |
|
93 | - * |
|
94 | - * @param string $cacheKey |
|
95 | - * @param string $namespace |
|
96 | - * @return void |
|
97 | - */ |
|
92 | + * Checks if a cache item exists. |
|
93 | + * |
|
94 | + * @param string $cacheKey |
|
95 | + * @param string $namespace |
|
96 | + * @return void |
|
97 | + */ |
|
98 | 98 | public function forever(string $cacheKey, mixed $cacheData) |
99 | 99 | { |
100 | 100 | $this->putCache($cacheKey, $cacheData, ttl: 31536000 * 1000); |
@@ -102,10 +102,10 @@ discard block |
||
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
105 | - * Flushes the entire cache. |
|
106 | - * |
|
107 | - * @return void |
|
108 | - */ |
|
105 | + * Flushes the entire cache. |
|
106 | + * |
|
107 | + * @return void |
|
108 | + */ |
|
109 | 109 | public function flushCache() |
110 | 110 | { |
111 | 111 | $this->cacheer->cacheStore->flushCache(); |
@@ -113,12 +113,12 @@ discard block |
||
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
116 | - * Gets a cache item by its key. |
|
117 | - * |
|
118 | - * @param string $cacheKey |
|
119 | - * @param string $namespace |
|
120 | - * @return bool |
|
121 | - */ |
|
116 | + * Gets a cache item by its key. |
|
117 | + * |
|
118 | + * @param string $cacheKey |
|
119 | + * @param string $namespace |
|
120 | + * @return bool |
|
121 | + */ |
|
122 | 122 | public function increment(string $cacheKey, int $amount = 1, string $namespace = '') |
123 | 123 | { |
124 | 124 | $cacheData = $this->cacheer->getCache($cacheKey, $namespace); |
@@ -133,13 +133,13 @@ discard block |
||
133 | 133 | } |
134 | 134 | |
135 | 135 | /** |
136 | - * Gets a cache item by its key. |
|
137 | - * |
|
138 | - * @param string $cacheKey |
|
139 | - * @param string $namespace |
|
140 | - * @param int|string $ttl |
|
141 | - * @return void |
|
142 | - */ |
|
136 | + * Gets a cache item by its key. |
|
137 | + * |
|
138 | + * @param string $cacheKey |
|
139 | + * @param string $namespace |
|
140 | + * @param int|string $ttl |
|
141 | + * @return void |
|
142 | + */ |
|
143 | 143 | public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
144 | 144 | { |
145 | 145 | $data = CacheerHelper::prepareForStorage($cacheData, $this->cacheer->isCompressionEnabled(), $this->cacheer->getEncryptionKey()); |
@@ -148,26 +148,26 @@ discard block |
||
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
151 | - * Puts multiple cache items in a batch. |
|
152 | - * |
|
153 | - * @param array $items |
|
154 | - * @param string $namespace |
|
155 | - * @param int $batchSize |
|
156 | - * @return void |
|
157 | - */ |
|
151 | + * Puts multiple cache items in a batch. |
|
152 | + * |
|
153 | + * @param array $items |
|
154 | + * @param string $namespace |
|
155 | + * @param int $batchSize |
|
156 | + * @return void |
|
157 | + */ |
|
158 | 158 | public function putMany(array $items, string $namespace = '', int $batchSize = 100) |
159 | 159 | { |
160 | 160 | $this->cacheer->cacheStore->putMany($items, $namespace, $batchSize); |
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
164 | - * Renews the cache item with a new TTL. |
|
165 | - * |
|
166 | - * @param string $cacheKey |
|
167 | - * @param int|string $ttl |
|
168 | - * @param string $namespace |
|
169 | - * @return void |
|
170 | - */ |
|
164 | + * Renews the cache item with a new TTL. |
|
165 | + * |
|
166 | + * @param string $cacheKey |
|
167 | + * @param int|string $ttl |
|
168 | + * @param string $namespace |
|
169 | + * @return void |
|
170 | + */ |
|
171 | 171 | public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = '') |
172 | 172 | { |
173 | 173 | $this->cacheer->cacheStore->renewCache($cacheKey, $ttl, $namespace); |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * @param int|string $ttl |
37 | 37 | * @return bool |
38 | 38 | */ |
39 | - public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
|
39 | + public function add(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600) |
|
40 | 40 | { |
41 | 41 | if (!empty($this->cacheer->getCache($cacheKey, $namespace))) { |
42 | 42 | return true; |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | * @param int|string $ttl |
141 | 141 | * @return void |
142 | 142 | */ |
143 | - public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int|string $ttl = 3600) |
|
143 | + public function putCache(string $cacheKey, mixed $cacheData, string $namespace = '', int | string $ttl = 3600) |
|
144 | 144 | { |
145 | 145 | $data = CacheerHelper::prepareForStorage($cacheData, $this->cacheer->isCompressionEnabled(), $this->cacheer->getEncryptionKey()); |
146 | 146 | $this->cacheer->cacheStore->putCache($cacheKey, $data, $namespace, $ttl); |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * @param string $namespace |
169 | 169 | * @return void |
170 | 170 | */ |
171 | - public function renewCache(string $cacheKey, int|string $ttl = 3600, string $namespace = '') |
|
171 | + public function renewCache(string $cacheKey, int | string $ttl = 3600, string $namespace = '') |
|
172 | 172 | { |
173 | 173 | $this->cacheer->cacheStore->renewCache($cacheKey, $ttl, $namespace); |
174 | 174 | $this->cacheer->syncState(); |