@@ -20,8 +20,8 @@ discard block |
||
20 | 20 | { |
21 | 21 | |
22 | 22 | /** |
23 | - * @var Cacheer |
|
24 | - */ |
|
23 | + * @var Cacheer |
|
24 | + */ |
|
25 | 25 | protected $cacheer; |
26 | 26 | |
27 | 27 | /** @param string $logPath */ |
@@ -38,10 +38,10 @@ discard block |
||
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | - * Uses the database driver for caching. |
|
42 | - * |
|
43 | - * @return Cacheer |
|
44 | - */ |
|
41 | + * Uses the database driver for caching. |
|
42 | + * |
|
43 | + * @return Cacheer |
|
44 | + */ |
|
45 | 45 | public function useDatabaseDriver() |
46 | 46 | { |
47 | 47 | $this->cacheer->cacheStore = new DatabaseCacheStore($this->logPath); |
@@ -49,10 +49,10 @@ discard block |
||
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
52 | - * Uses the file driver for caching. |
|
53 | - * |
|
54 | - * @return Cacheer |
|
55 | - */ |
|
52 | + * Uses the file driver for caching. |
|
53 | + * |
|
54 | + * @return Cacheer |
|
55 | + */ |
|
56 | 56 | public function useFileDriver() |
57 | 57 | { |
58 | 58 | $this->cacheer->options['loggerPath'] = $this->logPath; |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
64 | - * Uses the Redis driver for caching. |
|
65 | - * |
|
66 | - * @return Cacheer |
|
67 | - */ |
|
64 | + * Uses the Redis driver for caching. |
|
65 | + * |
|
66 | + * @return Cacheer |
|
67 | + */ |
|
68 | 68 | public function useRedisDriver() |
69 | 69 | { |
70 | 70 | $this->cacheer->cacheStore = new RedisCacheStore($this->logPath); |
@@ -72,10 +72,10 @@ discard block |
||
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
75 | - * Uses the array driver for caching. |
|
76 | - * |
|
77 | - * @return Cacheer |
|
78 | - */ |
|
75 | + * Uses the array driver for caching. |
|
76 | + * |
|
77 | + * @return Cacheer |
|
78 | + */ |
|
79 | 79 | public function useArrayDriver() |
80 | 80 | { |
81 | 81 | $this->cacheer->cacheStore = new ArrayCacheStore($this->logPath); |
@@ -83,10 +83,10 @@ discard block |
||
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
86 | - * Uses the default driver for caching. |
|
87 | - * |
|
88 | - * @return Cacheer |
|
89 | - */ |
|
86 | + * Uses the default driver for caching. |
|
87 | + * |
|
88 | + * @return Cacheer |
|
89 | + */ |
|
90 | 90 | public function useDefaultDriver() |
91 | 91 | { |
92 | 92 | if (!isset($this->cacheer->options['cacheDir'])) { |
@@ -103,16 +103,16 @@ discard block |
||
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
106 | - * Checks if the directory exists or creates it. |
|
107 | - * |
|
108 | - * @param mixed $dirName |
|
109 | - * @return bool |
|
110 | - */ |
|
106 | + * Checks if the directory exists or creates it. |
|
107 | + * |
|
108 | + * @param mixed $dirName |
|
109 | + * @return bool |
|
110 | + */ |
|
111 | 111 | private function isDir(mixed $dirName) |
112 | 112 | { |
113 | - if (is_dir($dirName)) { |
|
114 | - return true; |
|
115 | - } |
|
116 | - return mkdir($dirName, 0755, true); |
|
113 | + if (is_dir($dirName)) { |
|
114 | + return true; |
|
115 | + } |
|
116 | + return mkdir($dirName, 0755, true); |
|
117 | 117 | } |
118 | 118 | } |
@@ -13,20 +13,20 @@ discard block |
||
13 | 13 | private mixed $data; |
14 | 14 | |
15 | 15 | /** |
16 | - * CacheDataFormatter constructor. |
|
17 | - * |
|
18 | - * @param mixed $data |
|
19 | - */ |
|
16 | + * CacheDataFormatter constructor. |
|
17 | + * |
|
18 | + * @param mixed $data |
|
19 | + */ |
|
20 | 20 | public function __construct(mixed $data) |
21 | 21 | { |
22 | 22 | $this->data = $data; |
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
26 | - * Converts the data to JSON format. |
|
27 | - * |
|
28 | - * @return string|false |
|
29 | - */ |
|
26 | + * Converts the data to JSON format. |
|
27 | + * |
|
28 | + * @return string|false |
|
29 | + */ |
|
30 | 30 | public function toJson() |
31 | 31 | { |
32 | 32 | return json_encode( |
@@ -38,30 +38,30 @@ discard block |
||
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | - * Converts the data to an array. |
|
42 | - * |
|
43 | - * @return array |
|
44 | - */ |
|
41 | + * Converts the data to an array. |
|
42 | + * |
|
43 | + * @return array |
|
44 | + */ |
|
45 | 45 | public function toArray() |
46 | 46 | { |
47 | 47 | return (array)$this->data; |
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
51 | - * Converts the data to a string. |
|
52 | - * |
|
53 | - * @return string |
|
54 | - */ |
|
51 | + * Converts the data to a string. |
|
52 | + * |
|
53 | + * @return string |
|
54 | + */ |
|
55 | 55 | public function toString() |
56 | 56 | { |
57 | 57 | return (string)$this->data; |
58 | 58 | } |
59 | 59 | |
60 | 60 | /** |
61 | - * Converts the data to an object. |
|
62 | - * |
|
63 | - * @return object |
|
64 | - */ |
|
61 | + * Converts the data to an object. |
|
62 | + * |
|
63 | + * @return object |
|
64 | + */ |
|
65 | 65 | public function toObject() |
66 | 66 | { |
67 | 67 | return (object)$this->data; |
@@ -60,12 +60,12 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
63 | - * Retrieves cache data from the database. |
|
64 | - * |
|
65 | - * @param string $cacheKey |
|
66 | - * @param string $namespace |
|
67 | - * @return mixed |
|
68 | - */ |
|
63 | + * Retrieves cache data from the database. |
|
64 | + * |
|
65 | + * @param string $cacheKey |
|
66 | + * @param string $namespace |
|
67 | + * @return mixed |
|
68 | + */ |
|
69 | 69 | public function retrieve(string $cacheKey, string $namespace = '') |
70 | 70 | { |
71 | 71 | $driver = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME); |
@@ -85,11 +85,11 @@ discard block |
||
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
88 | - * Retrieves multiple cache items by their keys. |
|
89 | - * @param array $cacheKeys |
|
90 | - * @param string $namespace |
|
91 | - * @return array |
|
92 | - */ |
|
88 | + * Retrieves multiple cache items by their keys. |
|
89 | + * @param array $cacheKeys |
|
90 | + * @param string $namespace |
|
91 | + * @return array |
|
92 | + */ |
|
93 | 93 | public function getAll(string $namespace = '') |
94 | 94 | { |
95 | 95 | $driver = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME); |
@@ -110,10 +110,10 @@ discard block |
||
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
113 | - * Get Update query based on the database driver. |
|
114 | - * |
|
115 | - * @return string |
|
116 | - */ |
|
113 | + * Get Update query based on the database driver. |
|
114 | + * |
|
115 | + * @return string |
|
116 | + */ |
|
117 | 117 | private function getUpdateQueryWithDriver() |
118 | 118 | { |
119 | 119 | $driver = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME); |
@@ -124,10 +124,10 @@ discard block |
||
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
127 | - * Get Delete query based on the database driver. |
|
128 | - * |
|
129 | - * @return string |
|
130 | - */ |
|
127 | + * Get Delete query based on the database driver. |
|
128 | + * |
|
129 | + * @return string |
|
130 | + */ |
|
131 | 131 | private function getDeleteQueryWithDriver() |
132 | 132 | { |
133 | 133 | $driver = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME); |
@@ -138,13 +138,13 @@ discard block |
||
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
141 | - * Updates an existing cache item in the database. |
|
142 | - * |
|
143 | - * @param string $cacheKey |
|
144 | - * @param mixed $cacheData |
|
145 | - * @param string $namespace |
|
146 | - * @return bool |
|
147 | - */ |
|
141 | + * Updates an existing cache item in the database. |
|
142 | + * |
|
143 | + * @param string $cacheKey |
|
144 | + * @param mixed $cacheData |
|
145 | + * @param string $namespace |
|
146 | + * @return bool |
|
147 | + */ |
|
148 | 148 | public function update(string $cacheKey, mixed $cacheData, string $namespace = '') |
149 | 149 | { |
150 | 150 | $query = $this->getUpdateQueryWithDriver(); |
@@ -158,12 +158,12 @@ discard block |
||
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
161 | - * Clears a specific cache item from the database. |
|
162 | - * |
|
163 | - * @param string $cacheKey |
|
164 | - * @param string $namespace |
|
165 | - * @return bool |
|
166 | - */ |
|
161 | + * Clears a specific cache item from the database. |
|
162 | + * |
|
163 | + * @param string $cacheKey |
|
164 | + * @param string $namespace |
|
165 | + * @return bool |
|
166 | + */ |
|
167 | 167 | public function clear(string $cacheKey, string $namespace = '') |
168 | 168 | { |
169 | 169 | $query = $this->getDeleteQueryWithDriver(); |
@@ -176,10 +176,10 @@ discard block |
||
176 | 176 | } |
177 | 177 | |
178 | 178 | /** |
179 | - * Gets the query to renew the expiration time of a cache item based on the database driver. |
|
180 | - * |
|
181 | - * @return string |
|
182 | - */ |
|
179 | + * Gets the query to renew the expiration time of a cache item based on the database driver. |
|
180 | + * |
|
181 | + * @return string |
|
182 | + */ |
|
183 | 183 | private function getRenewExpirationQueryWithDriver(): string |
184 | 184 | { |
185 | 185 | $driver = $this->connection->getAttribute(PDO::ATTR_DRIVER_NAME); |
@@ -194,13 +194,13 @@ discard block |
||
194 | 194 | } |
195 | 195 | |
196 | 196 | /** |
197 | - * Checks if a cache item is valid based on its key, namespace, and current time. |
|
198 | - * |
|
199 | - * @param string $cacheKey |
|
200 | - * @param string $namespace |
|
201 | - * @param string $currentTime |
|
202 | - * @return bool |
|
203 | - */ |
|
197 | + * Checks if a cache item is valid based on its key, namespace, and current time. |
|
198 | + * |
|
199 | + * @param string $cacheKey |
|
200 | + * @param string $namespace |
|
201 | + * @param string $currentTime |
|
202 | + * @return bool |
|
203 | + */ |
|
204 | 204 | private function hasValidCache(string $cacheKey, string $namespace, string $currentTime): bool |
205 | 205 | { |
206 | 206 | $stmt = $this->connection->prepare( |
@@ -216,13 +216,13 @@ discard block |
||
216 | 216 | } |
217 | 217 | |
218 | 218 | /** |
219 | - * Renews the expiration time of a cache item. |
|
220 | - * |
|
221 | - * @param string $cacheKey |
|
222 | - * @param string|int $ttl |
|
223 | - * @param string $namespace |
|
224 | - * @return bool |
|
225 | - */ |
|
219 | + * Renews the expiration time of a cache item. |
|
220 | + * |
|
221 | + * @param string $cacheKey |
|
222 | + * @param string|int $ttl |
|
223 | + * @param string $namespace |
|
224 | + * @return bool |
|
225 | + */ |
|
226 | 226 | public function renew(string $cacheKey, string|int $ttl, string $namespace = '') |
227 | 227 | { |
228 | 228 | $currentTime = date('Y-m-d H:i:s'); |
@@ -242,32 +242,32 @@ discard block |
||
242 | 242 | } |
243 | 243 | |
244 | 244 | /** |
245 | - * Flushes all cache items from the database. |
|
246 | - * |
|
247 | - * @return bool |
|
248 | - */ |
|
245 | + * Flushes all cache items from the database. |
|
246 | + * |
|
247 | + * @return bool |
|
248 | + */ |
|
249 | 249 | public function flush() |
250 | 250 | { |
251 | 251 | return $this->connection->exec("DELETE FROM cacheer_table") !== false; |
252 | 252 | } |
253 | 253 | |
254 | 254 | /** |
255 | - * Serializes or unserializes data based on the provided flag. |
|
256 | - * |
|
257 | - * @param mixed $data |
|
258 | - * @return string |
|
259 | - */ |
|
255 | + * Serializes or unserializes data based on the provided flag. |
|
256 | + * |
|
257 | + * @param mixed $data |
|
258 | + * @return string |
|
259 | + */ |
|
260 | 260 | private function serialize(mixed $data, bool $serialize = true) |
261 | 261 | { |
262 | 262 | return $serialize ? serialize($data) : unserialize($data); |
263 | 263 | } |
264 | 264 | |
265 | 265 | /** |
266 | - * Gets the current date and time based on the database driver. |
|
267 | - * |
|
268 | - * @param string $driver |
|
269 | - * @return string |
|
270 | - */ |
|
266 | + * Gets the current date and time based on the database driver. |
|
267 | + * |
|
268 | + * @param string $driver |
|
269 | + * @return string |
|
270 | + */ |
|
271 | 271 | private function getCurrentDateTime(string $driver) |
272 | 272 | { |
273 | 273 | return ($driver === 'sqlite') ? "DATETIME('now', 'localtime')" : "NOW()"; |
@@ -13,112 +13,112 @@ |
||
13 | 13 | class TimeBuilder |
14 | 14 | { |
15 | 15 | |
16 | - /** @param string $unit */ |
|
17 | - private string $unit; |
|
18 | - |
|
19 | - /** @param int $value */ |
|
20 | - private int $value; |
|
21 | - |
|
22 | - /** @param Closure $callback */ |
|
23 | - private Closure $callback; |
|
24 | - |
|
25 | - /** @param FileOptionBuilder */ |
|
26 | - private $builder = null; |
|
27 | - |
|
28 | - /** |
|
29 | - * TimeBuilder constructor. |
|
30 | - * @param Closure $callback |
|
31 | - * @param FileOptionBuilder $builder |
|
32 | - * |
|
33 | - * @return void |
|
34 | - */ |
|
35 | - public function __construct(Closure $callback, $builder) |
|
36 | - { |
|
16 | + /** @param string $unit */ |
|
17 | + private string $unit; |
|
18 | + |
|
19 | + /** @param int $value */ |
|
20 | + private int $value; |
|
21 | + |
|
22 | + /** @param Closure $callback */ |
|
23 | + private Closure $callback; |
|
24 | + |
|
25 | + /** @param FileOptionBuilder */ |
|
26 | + private $builder = null; |
|
27 | + |
|
28 | + /** |
|
29 | + * TimeBuilder constructor. |
|
30 | + * @param Closure $callback |
|
31 | + * @param FileOptionBuilder $builder |
|
32 | + * |
|
33 | + * @return void |
|
34 | + */ |
|
35 | + public function __construct(Closure $callback, $builder) |
|
36 | + { |
|
37 | 37 | $this->callback = $callback; |
38 | 38 | $this->builder = $builder; |
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Sets the time in seconds. |
|
43 | - * |
|
44 | - * @param int $seconds |
|
45 | - * @return FileOptionBuilder|mixed |
|
46 | - */ |
|
47 | - public function second(int $seconds) |
|
48 | - { |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Sets the time in seconds. |
|
43 | + * |
|
44 | + * @param int $seconds |
|
45 | + * @return FileOptionBuilder|mixed |
|
46 | + */ |
|
47 | + public function second(int $seconds) |
|
48 | + { |
|
49 | 49 | return $this->setTime($seconds, "seconds"); |
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * Sets the time in minutes. |
|
54 | - * |
|
55 | - * @param int $minutes |
|
56 | - * @return FileOptionBuilder|mixed |
|
57 | - */ |
|
58 | - public function minute(int $minutes) |
|
59 | - { |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * Sets the time in minutes. |
|
54 | + * |
|
55 | + * @param int $minutes |
|
56 | + * @return FileOptionBuilder|mixed |
|
57 | + */ |
|
58 | + public function minute(int $minutes) |
|
59 | + { |
|
60 | 60 | return $this->setTime($minutes, "minutes"); |
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Sets the time in hours. |
|
65 | - * |
|
66 | - * @param int $hours |
|
67 | - * @return FileOptionBuilder|mixed |
|
68 | - */ |
|
69 | - public function hour(int $hours) |
|
70 | - { |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Sets the time in hours. |
|
65 | + * |
|
66 | + * @param int $hours |
|
67 | + * @return FileOptionBuilder|mixed |
|
68 | + */ |
|
69 | + public function hour(int $hours) |
|
70 | + { |
|
71 | 71 | return $this->setTime($hours, "hours"); |
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Sets the time in days. |
|
76 | - * |
|
77 | - * @param int $days |
|
78 | - * @return FileOptionBuilder|mixed |
|
79 | - */ |
|
80 | - public function day(int $days) |
|
81 | - { |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Sets the time in days. |
|
76 | + * |
|
77 | + * @param int $days |
|
78 | + * @return FileOptionBuilder|mixed |
|
79 | + */ |
|
80 | + public function day(int $days) |
|
81 | + { |
|
82 | 82 | return $this->setTime($days, "days"); |
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Sets the time in weeks. |
|
87 | - * |
|
88 | - * @param int $weeks |
|
89 | - * @return FileOptionBuilder|mixed |
|
90 | - */ |
|
91 | - public function week(int $weeks) |
|
92 | - { |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Sets the time in weeks. |
|
87 | + * |
|
88 | + * @param int $weeks |
|
89 | + * @return FileOptionBuilder|mixed |
|
90 | + */ |
|
91 | + public function week(int $weeks) |
|
92 | + { |
|
93 | 93 | return $this->setTime($weeks, "weeks"); |
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Sets the time in months. |
|
98 | - * |
|
99 | - * @param int $months |
|
100 | - * @return FileOptionBuilder|mixed |
|
101 | - */ |
|
102 | - public function month(int $months) |
|
103 | - { |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Sets the time in months. |
|
98 | + * |
|
99 | + * @param int $months |
|
100 | + * @return FileOptionBuilder|mixed |
|
101 | + */ |
|
102 | + public function month(int $months) |
|
103 | + { |
|
104 | 104 | return $this->setTime($months, "months"); |
105 | - } |
|
105 | + } |
|
106 | 106 | |
107 | 107 | |
108 | - /** |
|
109 | - * This method sets the time value and unit, and invokes the callback with the formatted string. |
|
110 | - * |
|
111 | - * @param int $value |
|
112 | - * @param string $unit |
|
113 | - * @return FileOptionBuilder |
|
114 | - */ |
|
115 | - private function setTime(int $value, string $unit) |
|
116 | - { |
|
108 | + /** |
|
109 | + * This method sets the time value and unit, and invokes the callback with the formatted string. |
|
110 | + * |
|
111 | + * @param int $value |
|
112 | + * @param string $unit |
|
113 | + * @return FileOptionBuilder |
|
114 | + */ |
|
115 | + private function setTime(int $value, string $unit) |
|
116 | + { |
|
117 | 117 | |
118 | 118 | $this->value = $value; |
119 | 119 | $this->unit = $unit; |
120 | - ($this->callback)("{$value} {$unit}"); |
|
120 | + ($this->callback)("{$value} {$unit}"); |
|
121 | 121 | return $this->builder; |
122 | - } |
|
122 | + } |
|
123 | 123 | |
124 | 124 | } |
@@ -43,18 +43,18 @@ |
||
43 | 43 | |
44 | 44 | |
45 | 45 | /** |
46 | - * @var CacheLogger |
|
47 | - */ |
|
46 | + * @var CacheLogger |
|
47 | + */ |
|
48 | 48 | private $logger = null; |
49 | 49 | |
50 | 50 | /** |
51 | - * @var FileCacheManager |
|
52 | - */ |
|
51 | + * @var FileCacheManager |
|
52 | + */ |
|
53 | 53 | private FileCacheManager $fileManager; |
54 | 54 | |
55 | 55 | /** |
56 | - * @var FileCacheFlusher |
|
57 | - */ |
|
56 | + * @var FileCacheFlusher |
|
57 | + */ |
|
58 | 58 | private FileCacheFlusher $flusher; |
59 | 59 | |
60 | 60 |
@@ -12,18 +12,18 @@ discard block |
||
12 | 12 | class FileCacheFlusher |
13 | 13 | { |
14 | 14 | /** |
15 | - * @var FileCacheManager |
|
16 | - */ |
|
15 | + * @var FileCacheManager |
|
16 | + */ |
|
17 | 17 | private FileCacheManager $fileManager; |
18 | 18 | |
19 | 19 | /** |
20 | - * @var string $cacheDir |
|
21 | - */ |
|
20 | + * @var string $cacheDir |
|
21 | + */ |
|
22 | 22 | private string $cacheDir; |
23 | 23 | |
24 | 24 | /** |
25 | - * @var string $lastFlushTimeFile |
|
26 | - */ |
|
25 | + * @var string $lastFlushTimeFile |
|
26 | + */ |
|
27 | 27 | private string $lastFlushTimeFile; |
28 | 28 | |
29 | 29 | /** |
@@ -40,10 +40,10 @@ discard block |
||
40 | 40 | } |
41 | 41 | |
42 | 42 | /** |
43 | - * Flushes all cache items and updates the last flush timestamp. |
|
44 | - * |
|
45 | - * @return void |
|
46 | - */ |
|
43 | + * Flushes all cache items and updates the last flush timestamp. |
|
44 | + * |
|
45 | + * @return void |
|
46 | + */ |
|
47 | 47 | public function flushCache() |
48 | 48 | { |
49 | 49 | $this->fileManager->clearDirectory($this->cacheDir); |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
54 | - * Handles the auto-flush functionality based on options. |
|
55 | - * |
|
56 | - * @param array $options |
|
57 | - * @return void |
|
58 | - */ |
|
54 | + * Handles the auto-flush functionality based on options. |
|
55 | + * |
|
56 | + * @param array $options |
|
57 | + * @return void |
|
58 | + */ |
|
59 | 59 | public function handleAutoFlush(array $options) |
60 | 60 | { |
61 | 61 | if (isset($options['flushAfter'])) { |
@@ -64,11 +64,11 @@ discard block |
||
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | - * Schedules a flush operation based on the provided interval. |
|
68 | - * |
|
69 | - * @param string $flushAfter |
|
70 | - * @return void |
|
71 | - */ |
|
67 | + * Schedules a flush operation based on the provided interval. |
|
68 | + * |
|
69 | + * @param string $flushAfter |
|
70 | + * @return void |
|
71 | + */ |
|
72 | 72 | private function scheduleFlush(string $flushAfter) |
73 | 73 | { |
74 | 74 | $flushAfterSeconds = CacheFileHelper::convertExpirationToSeconds($flushAfter); |
@@ -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); |
@@ -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); |
@@ -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 = [], bool $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): bool |
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 = ''): bool |
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 = ''): mixed |
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 = ''): mixed |
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): mixed |
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): mixed |
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 = ''): bool |
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 bool |
|
239 | - */ |
|
236 | + * Checks if the last operation was successful. |
|
237 | + * |
|
238 | + * @return bool |
|
239 | + */ |
|
240 | 240 | public function isSuccess(): bool |
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): mixed |
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): mixed |
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(): CacheConfig |
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(): CacheDriver |
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): void |
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(): string |
349 | 349 | { |
350 | 350 | return $this->message; |
@@ -393,32 +393,32 @@ discard block |
||
393 | 393 | } |
394 | 394 | |
395 | 395 | /** |
396 | - * Enables or disables the formatter for cache data. |
|
397 | - * |
|
398 | - * @return void |
|
399 | - */ |
|
396 | + * Enables or disables the formatter for cache data. |
|
397 | + * |
|
398 | + * @return void |
|
399 | + */ |
|
400 | 400 | public function useFormatter(): void |
401 | 401 | { |
402 | 402 | $this->formatted = !$this->formatted; |
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
406 | - * Validates the options provided for the Cacheer instance. |
|
407 | - * |
|
408 | - * @param array $options |
|
409 | - * @return void |
|
410 | - */ |
|
406 | + * Validates the options provided for the Cacheer instance. |
|
407 | + * |
|
408 | + * @param array $options |
|
409 | + * @return void |
|
410 | + */ |
|
411 | 411 | private function validateOptions(array $options): void |
412 | 412 | { |
413 | 413 | $this->options = $options; |
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
417 | - * Enable or disable data compression |
|
418 | - * |
|
419 | - * @param bool $status |
|
420 | - * @return $this |
|
421 | - */ |
|
417 | + * Enable or disable data compression |
|
418 | + * |
|
419 | + * @param bool $status |
|
420 | + * @return $this |
|
421 | + */ |
|
422 | 422 | public function useCompression(bool $status = true): Cacheer |
423 | 423 | { |
424 | 424 | $this->compression = $status; |
@@ -426,11 +426,11 @@ discard block |
||
426 | 426 | } |
427 | 427 | |
428 | 428 | /** |
429 | - * Enable encryption for cached data |
|
430 | - * |
|
431 | - * @param string $key |
|
432 | - * @return $this |
|
433 | - */ |
|
429 | + * Enable encryption for cached data |
|
430 | + * |
|
431 | + * @param string $key |
|
432 | + * @return $this |
|
433 | + */ |
|
434 | 434 | public function useEncryption(string $key): Cacheer |
435 | 435 | { |
436 | 436 | $this->encryptionKey = $key; |