[Cache] Psr16Cache does not handle Proxy cache items

This commit is contained in:
Alexandre Parent 2020-08-31 10:08:37 -04:00 committed by Nicolas Grekas
parent 6e59396ff9
commit e525fa1055
2 changed files with 31 additions and 0 deletions

View File

@ -44,6 +44,7 @@ class Psr16Cache implements CacheInterface, PruneableInterface, ResettableInterf
$createCacheItem = \Closure::bind(
static function ($key, $value, $allowInt = false) use (&$cacheItemPrototype) {
$item = clone $cacheItemPrototype;
$item->poolHash = $item->innerItem = null;
$item->key = $allowInt && \is_int($key) ? (string) $key : CacheItem::validateKey($key);
$item->value = $value;
$item->isHit = false;

View File

@ -0,0 +1,30 @@
<?php
namespace Symfony\Component\Cache\Tests;
use Cache\IntegrationTests\SimpleCacheTest;
use Psr\SimpleCache\CacheInterface;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\ProxyAdapter;
use Symfony\Component\Cache\Psr16Cache;
class Psr16CacheProxyTest extends SimpleCacheTest
{
public function createSimpleCache(int $defaultLifetime = 0): CacheInterface
{
return new Psr16Cache(new ProxyAdapter(new ArrayAdapter($defaultLifetime), 'my-namespace.'));
}
public function testProxy()
{
$pool = new ArrayAdapter();
$cache = new Psr16Cache(new ProxyAdapter($pool, 'my-namespace.'));
$this->assertNull($cache->get('some-key'));
$this->assertTrue($cache->set('some-other-key', 'value'));
$item = $pool->getItem('my-namespace.some-other-key', 'value');
$this->assertTrue($item->isHit());
$this->assertSame('value', $item->get());
}
}