22
33namespace Doctrine \Common \Cache ;
44
5+ use function array_combine ;
6+ use function array_key_exists ;
7+ use function array_map ;
8+ use function sprintf ;
9+
510/**
611 * Base class for cache provider implementations.
712 *
8- * @since 2.2
9- * @author Benjamin Eberlei <[email protected] > 10- * @author Guilherme Blanco <[email protected] > 11- * @author Jonathan Wage <[email protected] > 12- * @author Roman Borschel <[email protected] > 13- * @author Fabio B. Silva <[email protected] > 14- * @author Benoit Burnichon <[email protected] > 1513 */
1614abstract class CacheProvider implements Cache, FlushableCache, ClearableCache, MultiOperationCache
1715{
18- const DOCTRINE_NAMESPACE_CACHEKEY = 'DoctrineNamespaceCacheKey[%s] ' ;
16+ public const DOCTRINE_NAMESPACE_CACHEKEY = 'DoctrineNamespaceCacheKey[%s] ' ;
1917
2018 /**
2119 * The namespace to prefix all cache ids with.
@@ -27,7 +25,7 @@ abstract class CacheProvider implements Cache, FlushableCache, ClearableCache, M
2725 /**
2826 * The namespace version.
2927 *
30- * @var integer |null
28+ * @var int |null
3129 */
3230 private $ namespaceVersion ;
3331
@@ -79,9 +77,11 @@ public function fetchMultiple(array $keys)
7977 // no internal array function supports this sort of mapping: needs to be iterative
8078 // this filters and combines keys in one pass
8179 foreach ($ namespacedKeys as $ requestedKey => $ namespacedKey ) {
82- if (isset ($ items [$ namespacedKey ]) || array_key_exists ($ namespacedKey , $ items )) {
83- $ foundItems [ $ requestedKey ] = $ items [ $ namespacedKey ] ;
80+ if (! isset ($ items [$ namespacedKey ]) && ! array_key_exists ($ namespacedKey , $ items )) {
81+ continue ;
8482 }
83+
84+ $ foundItems [$ requestedKey ] = $ items [$ namespacedKey ];
8585 }
8686
8787 return $ foundItems ;
@@ -121,7 +121,7 @@ public function save($id, $data, $lifeTime = 0)
121121 */
122122 public function deleteMultiple (array $ keys )
123123 {
124- return $ this ->doDeleteMultiple (array_map (array ( $ this , 'getNamespacedId ' ) , $ keys ));
124+ return $ this ->doDeleteMultiple (array_map ([ $ this , 'getNamespacedId ' ] , $ keys ));
125125 }
126126
127127 /**
@@ -181,8 +181,6 @@ private function getNamespacedId(string $id) : string
181181
182182 /**
183183 * Returns the namespace cache key.
184- *
185- * @return string
186184 */
187185 private function getNamespaceCacheKey () : string
188186 {
@@ -191,12 +189,10 @@ private function getNamespaceCacheKey() : string
191189
192190 /**
193191 * Returns the namespace version.
194- *
195- * @return integer
196192 */
197193 private function getNamespaceVersion () : int
198194 {
199- if (null !== $ this ->namespaceVersion ) {
195+ if ($ this ->namespaceVersion !== null ) {
200196 return $ this ->namespaceVersion ;
201197 }
202198
@@ -217,9 +213,12 @@ protected function doFetchMultiple(array $keys)
217213 $ returnValues = [];
218214
219215 foreach ($ keys as $ key ) {
220- if (false !== ($ item = $ this ->doFetch ($ key )) || $ this ->doContains ($ key )) {
221- $ returnValues [$ key ] = $ item ;
216+ $ item = $ this ->doFetch ($ key );
217+ if ($ item === false && ! $ this ->doContains ($ key )) {
218+ continue ;
222219 }
220+
221+ $ returnValues [$ key ] = $ item ;
223222 }
224223
225224 return $ returnValues ;
@@ -246,9 +245,9 @@ abstract protected function doContains($id);
246245 /**
247246 * Default implementation of doSaveMultiple. Each driver that supports multi-put should override it.
248247 *
249- * @param array $keysAndValues Array of keys and values to save in cache
250- * @param int $lifetime The lifetime. If != 0, sets a specific lifetime for these
251- * cache entries (0 => infinite lifeTime).
248+ * @param array $keysAndValues Array of keys and values to save in cache
249+ * @param int $lifetime The lifetime. If != 0, sets a specific lifetime for these
250+ * cache entries (0 => infinite lifeTime).
252251 *
253252 * @return bool TRUE if the operation was successful, FALSE if it wasn't.
254253 */
@@ -257,9 +256,11 @@ protected function doSaveMultiple(array $keysAndValues, $lifetime = 0)
257256 $ success = true ;
258257
259258 foreach ($ keysAndValues as $ key => $ value ) {
260- if ( ! $ this ->doSave ($ key , $ value , $ lifetime )) {
261- $ success = false ;
259+ if ($ this ->doSave ($ key , $ value , $ lifetime )) {
260+ continue ;
262261 }
262+
263+ $ success = false ;
263264 }
264265
265266 return $ success ;
@@ -289,9 +290,11 @@ protected function doDeleteMultiple(array $keys)
289290 $ success = true ;
290291
291292 foreach ($ keys as $ key ) {
292- if ( ! $ this ->doDelete ($ key )) {
293- $ success = false ;
293+ if ($ this ->doDelete ($ key )) {
294+ continue ;
294295 }
296+
297+ $ success = false ;
295298 }
296299
297300 return $ success ;
@@ -316,8 +319,6 @@ abstract protected function doFlush();
316319 /**
317320 * Retrieves cached information from the data store.
318321 *
319- * @since 2.2
320- *
321322 * @return array|null An associative array with server's statistics if available, NULL otherwise.
322323 */
323324 abstract protected function doGetStats ();
0 commit comments