Hash cache keys on save

This commit is contained in:
Lars Strojny 2017-08-02 15:53:45 +02:00 committed by Nicolas Grekas
parent 468b44a031
commit 94b1b12b55
3 changed files with 9 additions and 4 deletions

View File

@ -55,19 +55,20 @@ abstract class AbstractAdapter implements AdapterInterface, LoggerAwareInterface
null,
CacheItem::class
);
$getId = function ($key) { return $this->getId((string) $key); };
$this->mergeByLifetime = \Closure::bind(
function ($deferred, $namespace, &$expiredIds) {
function ($deferred, $namespace, &$expiredIds) use ($getId) {
$byLifetime = array();
$now = time();
$expiredIds = array();
foreach ($deferred as $key => $item) {
if (null === $item->expiry) {
$byLifetime[0 < $item->defaultLifetime ? $item->defaultLifetime : 0][$namespace.$key] = $item->value;
$byLifetime[0 < $item->defaultLifetime ? $item->defaultLifetime : 0][$getId($key)] = $item->value;
} elseif ($item->expiry > $now) {
$byLifetime[$item->expiry - $now][$namespace.$key] = $item->value;
$byLifetime[$item->expiry - $now][$getId($key)] = $item->value;
} else {
$expiredIds[] = $namespace.$key;
$expiredIds[] = $getId($key);
}
}

View File

@ -22,6 +22,7 @@ class PhpArrayAdapterTest extends AdapterTestCase
{
protected $skippedTests = array(
'testBasicUsage' => 'PhpArrayAdapter is read-only.',
'testBasicUsageWithLongKey' => 'PhpArrayAdapter is read-only.',
'testClear' => 'PhpArrayAdapter is read-only.',
'testClearWithDeferredItems' => 'PhpArrayAdapter is read-only.',
'testDeleteItem' => 'PhpArrayAdapter is read-only.',

View File

@ -21,6 +21,8 @@ use Symfony\Component\Cache\Simple\PhpArrayCache;
class PhpArrayCacheTest extends CacheTestCase
{
protected $skippedTests = array(
'testBasicUsageWithLongKey' => 'PhpArrayCache does no writes',
'testDelete' => 'PhpArrayCache does no writes',
'testDeleteMultiple' => 'PhpArrayCache does no writes',
'testDeleteMultipleGenerator' => 'PhpArrayCache does no writes',
@ -57,6 +59,7 @@ class PhpArrayCacheTest extends CacheTestCase
FilesystemAdapterTest::rmdir(sys_get_temp_dir().'/symfony-cache');
}
}
public function createSimpleCache()
{
return new PhpArrayCacheWrapper(self::$file, new NullCache());