1 | <?php |
||
8 | class CCachePool implements \Psr\Cache\CacheItemPoolInterface |
||
9 | { |
||
10 | /** |
||
11 | * An array with all cache items, |
||
12 | * @var \Psr\Cache\CacheItemInterface[] |
||
13 | */ |
||
14 | private $cacheItems; |
||
15 | |||
16 | /** |
||
17 | * An array of items to be saved later |
||
18 | * @var \Psr\Cache\CacheItemInterface[] |
||
19 | */ |
||
20 | private $defferedItems; |
||
21 | |||
22 | /** |
||
23 | * The path to the cache items |
||
24 | * @var string |
||
25 | */ |
||
26 | static public $path; |
||
27 | |||
28 | /** |
||
29 | * Inits one array with the cached items and one with the deffered |
||
30 | * |
||
31 | */ |
||
32 | 12 | public function __construct() |
|
47 | |||
48 | /** |
||
49 | * Used to fill the array with existing cache items |
||
50 | * |
||
51 | * @return void |
||
52 | */ |
||
53 | 9 | private function initCache() |
|
72 | |||
73 | /** |
||
74 | * Returns the path where the cache items are stored |
||
75 | * @return string The path |
||
76 | */ |
||
77 | 12 | public static function getPath() |
|
81 | |||
82 | /** |
||
83 | * Returns a Cache Item representing the specified key. |
||
84 | * |
||
85 | * This method must always return a CacheItemInterface object, even in case of |
||
86 | * a cache miss. It MUST NOT return null. |
||
87 | * |
||
88 | * @param string $key |
||
89 | * The key for which to return the corresponding Cache Item. |
||
90 | * |
||
91 | * @throws InvalidArgumentException |
||
92 | * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException |
||
93 | * MUST be thrown. |
||
94 | * |
||
95 | * @return \Psr\Cache\CacheItemInterface |
||
96 | * The corresponding Cache Item. |
||
97 | */ |
||
98 | 5 | public function getItem($key) |
|
116 | |||
117 | /** |
||
118 | * Generates a key from a string. |
||
119 | * |
||
120 | * @param string $str |
||
121 | * The value to convert to a key-string, must be unique |
||
122 | * |
||
123 | * @return string |
||
124 | * A generated key-string |
||
125 | */ |
||
126 | public function generateKey($str) |
||
131 | |||
132 | /** |
||
133 | * Checks if a key string is valid, invalid values are {}()/\@: |
||
134 | * |
||
135 | * @param string $key |
||
136 | * A string to ckeck, invalid values are {}()/\@: |
||
137 | * |
||
138 | * @throws InvalidArgumentException |
||
139 | * If $key are not a legal value |
||
140 | * |
||
141 | * @return void |
||
142 | */ |
||
143 | 7 | public function checkKey($key) |
|
153 | |||
154 | /** |
||
155 | * Returns a traversable set of cache items. |
||
156 | * |
||
157 | * @param array $keys |
||
158 | * An indexed array of keys of items to retrieve. |
||
159 | * @throws InvalidArgumentException |
||
160 | * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException |
||
161 | * MUST be thrown. |
||
162 | * |
||
163 | * @return array|\Traversable |
||
164 | * A traversable collection of Cache Items keyed by the cache keys of |
||
165 | * each item. A Cache item will be returned for each key, even if that |
||
166 | * key is not found. However, if no keys are specified then an empty |
||
167 | * traversable MUST be returned instead. |
||
168 | */ |
||
169 | public function getItems(array $keys = array()) |
||
185 | |||
186 | /** |
||
187 | * Confirms if the cache contains specified cache item. |
||
188 | * |
||
189 | * Note: This method MAY avoid retrieving the cached value for performance reasons. |
||
190 | * This could result in a race condition with CacheItemInterface::get(). To avoid |
||
191 | * such situation use CacheItemInterface::isHit() instead. |
||
192 | * |
||
193 | * @param string $key |
||
194 | * The key for which to check existence. |
||
195 | * |
||
196 | * @throws InvalidArgumentException |
||
197 | * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException |
||
198 | * MUST be thrown. |
||
199 | * |
||
200 | * @return bool |
||
201 | * True if item exists in the cache, false otherwise. |
||
202 | */ |
||
203 | public function hasItem($key) |
||
217 | |||
218 | /** |
||
219 | * Deletes all items in the pool. |
||
220 | * |
||
221 | * @return bool |
||
222 | * True if the pool was successfully cleared. False if there was an error. |
||
223 | */ |
||
224 | public function clear() |
||
237 | |||
238 | /** |
||
239 | * Removes the item from the pool. |
||
240 | * |
||
241 | * @param string $key |
||
242 | * The key for which to delete |
||
243 | * |
||
244 | * @throws InvalidArgumentException |
||
245 | * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException |
||
246 | * MUST be thrown. |
||
247 | * |
||
248 | * @return bool |
||
249 | * True if the item was successfully removed. False if there was an error. |
||
250 | */ |
||
251 | 1 | public function deleteItem($key) |
|
270 | |||
271 | /** |
||
272 | * Removes multiple items from the pool. |
||
273 | * |
||
274 | * @param array $keys |
||
275 | * An array of keys that should be removed from the pool. |
||
276 | |||
277 | * @throws InvalidArgumentException |
||
278 | * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException |
||
279 | * MUST be thrown. |
||
280 | * |
||
281 | * @return bool |
||
282 | * True if the items were successfully removed. False if there was an error. |
||
283 | */ |
||
284 | 1 | public function deleteItems(array $keys) |
|
298 | |||
299 | /** |
||
300 | * Persists a cache item immediately. |
||
301 | * |
||
302 | * @param \Psr\Cache\CacheItemInterface $item |
||
303 | * The cache item to save. |
||
304 | * |
||
305 | * @return bool |
||
306 | * True if the item was successfully persisted. False if there was an error. |
||
307 | */ |
||
308 | 2 | public function save(\Psr\Cache\CacheItemInterface $item) |
|
327 | |||
328 | /** |
||
329 | * Sets a cache item to be persisted later. |
||
330 | * |
||
331 | * @param \Psr\Cache\CacheItemInterface $item |
||
332 | * The cache item to save. |
||
333 | * |
||
334 | * @return bool |
||
335 | * False if the item could not be queued or if a commit was attempted and failed. True otherwise. |
||
336 | */ |
||
337 | 1 | public function saveDeferred(\Psr\Cache\CacheItemInterface $item) |
|
353 | |||
354 | /** |
||
355 | * Persists any deferred cache items. |
||
356 | * |
||
357 | * @return bool |
||
358 | * True if all not-yet-saved items were successfully saved or there were none. False otherwise. |
||
359 | */ |
||
360 | 1 | public function commit() |
|
373 | } |
||
374 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.