Browse Source

Merge pull request #12584 from cakephp/3.7-simplecache-setmultiple

SimpleCacheEngine::setMultiple() should return boolean as dictated by CacheInterface
Mark Story 7 years ago
parent
commit
250376546b

+ 4 - 3
src/Cache/Cache.php

@@ -329,15 +329,16 @@ class Cache
      */
     public static function writeMany($data, $config = 'default')
     {
-        $backend = static::pool($config);
-        $return = $backend->setMultiple($data);
+        $engine = static::engine($config);
+
+        $return = $engine->writeMany($data);
         foreach ($return as $key => $success) {
             if ($success === false && $data[$key] !== '') {
                 throw new RuntimeException(sprintf(
                     '%s cache was unable to write \'%s\' to %s cache',
                     $config,
                     $key,
-                    get_class($backend)
+                    get_class($engine)
                 ));
             }
         }

+ 0 - 8
src/Cache/Engine/NullEngine.php

@@ -50,14 +50,6 @@ class NullEngine extends CacheEngine
     /**
      * {@inheritDoc}
      */
-    public function writeMany($data)
-    {
-        return true;
-    }
-
-    /**
-     * {@inheritDoc}
-     */
     public function read($key)
     {
         return false;

+ 10 - 1
src/Cache/SimpleCacheEngine.php

@@ -191,12 +191,21 @@ class SimpleCacheEngine implements CacheInterface
             $this->innerEngine->setConfig('duration', $ttl);
         }
         try {
-            return $this->innerEngine->writeMany($values);
+            $result = $this->innerEngine->writeMany($values);
+            foreach ($result as $key => $success) {
+                if ($success === false) {
+                    return false;
+                }
+            }
+
+            return true;
         } finally {
             if (isset($restore)) {
                 $this->innerEngine->setConfig('duration', $restore);
             }
         }
+
+        return false;
     }
 
     /**

+ 3 - 1
tests/TestCase/Cache/SimpleCacheEngineTest.php

@@ -292,7 +292,9 @@ class SimpleCacheEngineTest extends TestCase
             'key2' => 'other value',
             'key' => 'a value',
         ];
-        $this->cache->setMultiple($data);
+
+        $result = $this->cache->setMultiple($data);
+        $this->assertTrue($result);
 
         $results = $this->cache->getMultiple(array_keys($data));
         $this->assertEquals($expected, $results);