Skip to content

Commit

Permalink
SimpleCacheEngine::setMultiple() should return boolean as dictated by…
Browse files Browse the repository at this point in the history
… CacheInterface.
  • Loading branch information
ADmad committed Sep 22, 2018
1 parent 67a181d commit 7c11214
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/Cache/Cache.php
Expand Up @@ -329,15 +329,16 @@ public static function write($key, $value, $config = 'default')
*/
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)
));
}
}
Expand Down
8 changes: 0 additions & 8 deletions src/Cache/Engine/NullEngine.php
Expand Up @@ -47,14 +47,6 @@ public function write($key, $value)
return true;
}

/**
* {@inheritDoc}
*/
public function writeMany($data)
{
return true;
}

/**
* {@inheritDoc}
*/
Expand Down
11 changes: 10 additions & 1 deletion src/Cache/SimpleCacheEngine.php
Expand Up @@ -191,12 +191,21 @@ public function setMultiple($values, $ttl = null)
$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;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion tests/TestCase/Cache/SimpleCacheEngineTest.php
Expand Up @@ -292,7 +292,9 @@ public function testSetMultiple()
'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);
Expand Down

0 comments on commit 7c11214

Please sign in to comment.