Skip to content

Commit e525fa1

Browse files
alex-devnicolas-grekas
authored andcommitted
[Cache] Psr16Cache does not handle Proxy cache items
1 parent 6e59396 commit e525fa1

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Symfony/Component/Cache/Psr16Cache.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function __construct(CacheItemPoolInterface $pool)
4444
$createCacheItem = \Closure::bind(
4545
static function ($key, $value, $allowInt = false) use (&$cacheItemPrototype) {
4646
$item = clone $cacheItemPrototype;
47+
$item->poolHash = $item->innerItem = null;
4748
$item->key = $allowInt && \is_int($key) ? (string) $key : CacheItem::validateKey($key);
4849
$item->value = $value;
4950
$item->isHit = false;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Symfony\Component\Cache\Tests;
4+
5+
use Cache\IntegrationTests\SimpleCacheTest;
6+
use Psr\SimpleCache\CacheInterface;
7+
use Symfony\Component\Cache\Adapter\ArrayAdapter;
8+
use Symfony\Component\Cache\Adapter\ProxyAdapter;
9+
use Symfony\Component\Cache\Psr16Cache;
10+
11+
class Psr16CacheProxyTest extends SimpleCacheTest
12+
{
13+
public function createSimpleCache(int $defaultLifetime = 0): CacheInterface
14+
{
15+
return new Psr16Cache(new ProxyAdapter(new ArrayAdapter($defaultLifetime), 'my-namespace.'));
16+
}
17+
18+
public function testProxy()
19+
{
20+
$pool = new ArrayAdapter();
21+
$cache = new Psr16Cache(new ProxyAdapter($pool, 'my-namespace.'));
22+
23+
$this->assertNull($cache->get('some-key'));
24+
$this->assertTrue($cache->set('some-other-key', 'value'));
25+
26+
$item = $pool->getItem('my-namespace.some-other-key', 'value');
27+
$this->assertTrue($item->isHit());
28+
$this->assertSame('value', $item->get());
29+
}
30+
}

0 commit comments

Comments
 (0)