1 | <?php |
||
2 | /** |
||
3 | * This file is part of the O2System Framework package. |
||
4 | * |
||
5 | * For the full copyright and license information, please view the LICENSE |
||
6 | * file that was distributed with this source code. |
||
7 | * |
||
8 | * @author Steeve Andrian Salim |
||
9 | * @copyright Copyright (c) Steeve Andrian Salim |
||
10 | */ |
||
11 | |||
12 | // ------------------------------------------------------------------------ |
||
13 | |||
14 | namespace O2System\Cache\Adapters\Memcache; |
||
15 | |||
16 | // ------------------------------------------------------------------------ |
||
17 | |||
18 | use O2System\Cache\Item; |
||
19 | use Psr\Cache\CacheItemInterface; |
||
0 ignored issues
–
show
|
|||
20 | use Psr\Cache\CacheItemPoolInterface; |
||
0 ignored issues
–
show
The type
Psr\Cache\CacheItemPoolInterface was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
21 | use O2System\Spl\Exceptions\Logic\InvalidArgumentException; |
||
22 | |||
23 | /** |
||
24 | * Class ItemPool |
||
25 | * |
||
26 | * @package O2System\Cache\Adapters\File |
||
27 | */ |
||
28 | class ItemPool extends Adapter implements CacheItemPoolInterface |
||
29 | { |
||
30 | /** |
||
31 | * ItemPool::getItems |
||
32 | * |
||
33 | * Returns a traversable set of cache items. |
||
34 | * |
||
35 | * @param string[] $keys |
||
36 | * An indexed array of keys of items to retrieve. |
||
37 | * |
||
38 | * @throws InvalidArgumentException |
||
39 | * If any of the keys in $keys are not a legal value a \Psr\Cache\InvalidArgumentException |
||
40 | * MUST be thrown. |
||
41 | * |
||
42 | * @return array|\Traversable |
||
43 | * A traversable collection of Cache Items keyed by the cache keys of |
||
44 | * each item. A Cache item will be returned for each key, even if that |
||
45 | * key is not found. However, if no keys are specified then an empty |
||
46 | * traversable MUST be returned instead. |
||
47 | */ |
||
48 | public function getItems(array $keys = []) |
||
49 | { |
||
50 | if ( ! is_array($keys)) { |
||
0 ignored issues
–
show
|
|||
51 | throw new InvalidArgumentException('E_INVALID_ARGUMENT_ARRAY_CACHE_EXCEPTION'); |
||
52 | } |
||
53 | |||
54 | $items = []; |
||
55 | |||
56 | if (empty($keys)) { |
||
57 | $allItems = $this->memcache->getExtendedStats('items'); |
||
58 | |||
59 | foreach ($allItems as $server => $metadata) { |
||
60 | foreach ($metadata[ 'items' ] AS $itemKey => $itemMetadata) { |
||
61 | $cacheDump = $this->memcache->getExtendedStats('cachedump', (int)$itemKey); |
||
62 | |||
63 | foreach ($cacheDump[ $server ] AS $cacheDumpItemKey => $cacheDumpItemMetadata) { |
||
64 | $items[] = $this->getItem(str_replace($this->prefixKey, '', $cacheDumpItemKey)); |
||
65 | } |
||
66 | } |
||
67 | } |
||
68 | } elseif (count($keys)) { |
||
69 | foreach ($keys as $key) { |
||
70 | $items[] = $this->getItem($key); |
||
71 | } |
||
72 | } |
||
73 | |||
74 | return $items; |
||
75 | } |
||
76 | |||
77 | // ------------------------------------------------------------------------ |
||
78 | |||
79 | /** |
||
80 | * ItemPool::getKey |
||
81 | * |
||
82 | * Returns a Cache Item representing the specified key. |
||
83 | * |
||
84 | * This method must always return a CacheItemInterface object, even in case of |
||
85 | * a cache miss. It MUST NOT return null. |
||
86 | * |
||
87 | * @param string $key |
||
88 | * The key for which to return the corresponding Cache Item. |
||
89 | * |
||
90 | * @throws InvalidArgumentException |
||
91 | * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException |
||
92 | * MUST be thrown. |
||
93 | * |
||
94 | * @return CacheItemInterface |
||
95 | * The corresponding Cache Item. |
||
96 | */ |
||
97 | public function getItem($key) |
||
98 | { |
||
99 | if ( ! is_string($key)) { |
||
0 ignored issues
–
show
|
|||
100 | throw new InvalidArgumentException('E_INVALID_ARGUMENT_STRING_CACHE_EXCEPTION'); |
||
101 | } |
||
102 | |||
103 | $metadata = $this->memcache->get($this->prefixKey . $key); |
||
104 | $metadata = isset($metadata[ 0 ]) ? $metadata[ 0 ] : $metadata; |
||
105 | |||
106 | return new Item($key, $metadata); |
||
107 | } |
||
108 | |||
109 | // ------------------------------------------------------------------------ |
||
110 | |||
111 | /** |
||
112 | * ItemPool::hasItem |
||
113 | * |
||
114 | * Confirms if the cache contains specified cache item. |
||
115 | * |
||
116 | * Note: This method MAY avoid retrieving the cached value for performance reasons. |
||
117 | * This could result in a race condition with CacheItemInterface::get(). To avoid |
||
118 | * such situation use CacheItemInterface::isHit() instead. |
||
119 | * |
||
120 | * @param string $key |
||
121 | * The key for which to check existence. |
||
122 | * |
||
123 | * @throws InvalidArgumentException |
||
124 | * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException |
||
125 | * MUST be thrown. |
||
126 | * |
||
127 | * @return bool |
||
128 | * True if item exists in the cache, false otherwise. |
||
129 | */ |
||
130 | public function hasItem($key) |
||
131 | { |
||
132 | if ( ! is_string($key)) { |
||
0 ignored issues
–
show
|
|||
133 | throw new InvalidArgumentException('E_INVALID_ARGUMENT_STRING_CACHE_EXCEPTION'); |
||
134 | } |
||
135 | |||
136 | return (bool)$this->memcache->get($this->prefixKey . $key); |
||
137 | } |
||
138 | |||
139 | // ------------------------------------------------------------------------ |
||
140 | |||
141 | /** |
||
142 | * ItemPool::clear |
||
143 | * |
||
144 | * Deletes all items in the pool. |
||
145 | * |
||
146 | * @return bool |
||
147 | * True if the pool was successfully cleared. False if there was an error. |
||
148 | */ |
||
149 | public function clear() |
||
150 | { |
||
151 | return $this->memcache->flush(); |
||
152 | } |
||
153 | |||
154 | // ------------------------------------------------------------------------ |
||
155 | |||
156 | /** |
||
157 | * ItemPool::deleteItem |
||
158 | * |
||
159 | * Removes the item from the pool. |
||
160 | * |
||
161 | * @param string $key |
||
162 | * The key to delete. |
||
163 | * |
||
164 | * @throws InvalidArgumentException |
||
165 | * If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException |
||
166 | * MUST be thrown. |
||
167 | * |
||
168 | * @return bool |
||
169 | * True if the item was successfully removed. False if there was an error. |
||
170 | */ |
||
171 | public function deleteItem($key) |
||
172 | { |
||
173 | if ( ! is_string($key)) { |
||
0 ignored issues
–
show
|
|||
174 | throw new InvalidArgumentException('E_INVALID_ARGUMENT_STRING_CACHE_EXCEPTION'); |
||
175 | } |
||
176 | |||
177 | return $this->memcache->delete($this->prefixKey . $key); |
||
178 | } |
||
179 | |||
180 | // ------------------------------------------------------------------------ |
||
181 | |||
182 | /** |
||
183 | * ItemPool::save |
||
184 | * |
||
185 | * Persists a cache item immediately. |
||
186 | * |
||
187 | * @param CacheItemInterface $item |
||
188 | * The cache item to save. |
||
189 | * |
||
190 | * @return bool |
||
191 | * True if the item was successfully persisted. False if there was an error. |
||
192 | */ |
||
193 | public function save(CacheItemInterface $item) |
||
194 | { |
||
195 | $metadata = $item->getMetadata(); |
||
196 | $metadata[ 'data' ] = $item->get(); |
||
197 | |||
198 | if (extension_loaded('zlib')) { |
||
199 | return $this->memcache->set( |
||
200 | $this->prefixKey . $item->getKey(), |
||
201 | $metadata, |
||
202 | MEMCACHE_COMPRESSED, |
||
203 | $metadata[ 'ttl' ] |
||
204 | ); |
||
205 | } else { |
||
206 | return $this->memcache->set($this->prefixKey . $item->getKey(), $metadata, 0, $metadata[ 'ttl' ]); |
||
207 | } |
||
208 | } |
||
209 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths