8000 [Cache] fix Simple\Psr6Cache proxying of metadata · symfony/symfony@02edc9b · GitHub
[go: up one dir, main page]

Skip to content

Commit 02edc9b

Browse files
[Cache] fix Simple\Psr6Cache proxying of metadata
1 parent 64e2449 commit 02edc9b

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/Symfony/Component/Cache/Simple/Psr6Cache.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class Psr6Cache implements CacheInterface, PruneableInterface, ResettableInterfa
2929
{
3030
use ProxyTrait;
3131

32+
private const METADATA_EXPIRY_OFFSET = 1527506807;
33+
3234
private $createCacheItem;
3335
private $cacheItemPrototype;
3436

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

61-
return $createCacheItem($key, $value, $allowInt);
63+
return $createCacheItem($key, null, $allowInt)->set($value);
6264
};
6365
}
6466

@@ -147,8 +149,29 @@ public function getMultiple($keys, $default = null)
147149
}
148150
$values = array();
149151

152+
if (!$this->pool instanceof AdapterInterface) {
153+
foreach ($items as $key => $item) {
154+
$values[$key] = $item->isHit() ? $item->get() : $default;
155+
}
156+
157+
return $value;
158+
}
159+
150160
foreach ($items as $key => $item) {
151-
$values[$key] = $item->isHit() ? $item->get() : $default;
161+
if (!$item->isHit()) {
162+
$values[$key] = $default;
163+
continue;
164+
}
165+
$values[$key] = $item->get();
166+
167+
if (!$metadata = $item->getMetadata()) {
168+
continue;
169+
}
170+
unset($metadata[CacheItem::METADATA_TAGS]);
171+
172+
if ($metadata) {
173+
$values[$key] = array("\x9D".pack('VN', (int) $metadata[CacheItem::METADATA_EXPIRY] - self::METADATA_EXPIRY_OFFSET, $metadata[CacheItem::METADATA_CTIME])."\x5F" => $values[$key]);
174+
}
152175
}
153176

154177
return $values;

src/Symfony/Component/Cache/Tests/Adapter/SimpleCacheAdapterTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111

1212
namespace Symfony\Component\Cache\Tests\Adapter;
1313

14+
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
1415
use Symfony\Component\Cache\Adapter\SimpleCacheAdapter;
15-
use Symfony\Component\Cache\Simple\FilesystemCache;
16+
use Symfony\Component\Cache\Simple\Psr6Cache;
1617

1718
/**
1819
* @group time-sensitive
@@ -25,6 +26,6 @@ class SimpleCacheAdapterTest extends AdapterTestCase
2526

2627
public function createCachePool($defaultLifetime = 0)
2728
{
28-
return new SimpleCacheAdapter(new FilesystemCache(), '', $defaultLifetime);
29+
return new SimpleCacheAdapter(new Psr6Cache(new FilesystemAdapter()), '', $defaultLifetime);
2930
}
3031
}

0 commit comments

Comments
 (0)
0