Skip to content

[Cache] fix Simple\Psr6Cache proxying of metadata #29648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/Symfony/Component/Cache/Simple/Psr6Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class Psr6Cache implements CacheInterface, PruneableInterface, ResettableInterfa
{
use ProxyTrait;

private const METADATA_EXPIRY_OFFSET = 1527506807;

private $createCacheItem;
private $cacheItemPrototype;

Expand Down Expand Up @@ -58,7 +60,7 @@ function ($key, $value, $allowInt = false) use (&$cacheItemPrototype) {
}
$this->createCacheItem = $createCacheItem;

return $createCacheItem($key, $value, $allowInt);
return $createCacheItem($key, null, $allowInt)->set($value);
};
}

Expand Down Expand Up @@ -147,8 +149,29 @@ public function getMultiple($keys, $default = null)
}
$values = array();

if (!$this->pool instanceof AdapterInterface) {
foreach ($items as $key => $item) {
$values[$key] = $item->isHit() ? $item->get() : $default;
}

return $value;
}

foreach ($items as $key => $item) {
$values[$key] = $item->isHit() ? $item->get() : $default;
if (!$item->isHit()) {
$values[$key] = $default;
continue;
}
$values[$key] = $item->get();

if (!$metadata = $item->getMetadata()) {
continue;
}
unset($metadata[CacheItem::METADATA_TAGS]);

if ($metadata) {
$values[$key] = array("\x9D".pack('VN', (int) $metadata[CacheItem::METADATA_EXPIRY] - self::METADATA_EXPIRY_OFFSET, $metadata[CacheItem::METADATA_CTIME])."\x5F" => $values[$key]);
}
}

return $values;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

namespace Symfony\Component\Cache\Tests\Adapter;

use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\SimpleCacheAdapter;
use Symfony\Component\Cache\Simple\FilesystemCache;
use Symfony\Component\Cache\Simple\Psr6Cache;

/**
* @group time-sensitive
Expand All @@ -25,6 +26,6 @@ class SimpleCacheAdapterTest extends AdapterTestCase

public function createCachePool($defaultLifetime = 0)
{
return new SimpleCacheAdapter(new FilesystemCache(), '', $defaultLifetime);
return new SimpleCacheAdapter(new Psr6Cache(new FilesystemAdapter()), '', $defaultLifetime);
}
}