bug #38010 [Cache] Psr16Cache does not handle Proxy cache items (alex-dev)
This PR was merged into the 4.4 branch.
Discussion
----------
[Cache] Psr16Cache does not handle Proxy cache items
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix #38006
| License | MIT
Add test for Psr16Cache along with a ProxyAdapter
Commits
-------
e525fa1055
[Cache] Psr16Cache does not handle Proxy cache items
This commit is contained in:
commit
6bebe86d5a
@ -44,6 +44,7 @@ class Psr16Cache implements CacheInterface, PruneableInterface, ResettableInterf
|
|||||||
$createCacheItem = \Closure::bind(
|
$createCacheItem = \Closure::bind(
|
||||||
static function ($key, $value, $allowInt = false) use (&$cacheItemPrototype) {
|
static function ($key, $value, $allowInt = false) use (&$cacheItemPrototype) {
|
||||||
$item = clone $cacheItemPrototype;
|
$item = clone $cacheItemPrototype;
|
||||||
|
$item->poolHash = $item->innerItem = null;
|
||||||
$item->key = $allowInt && \is_int($key) ? (string) $key : CacheItem::validateKey($key);
|
$item->key = $allowInt && \is_int($key) ? (string) $key : CacheItem::validateKey($key);
|
||||||
$item->value = $value;
|
$item->value = $value;
|
||||||
$item->isHit = false;
|
$item->isHit = false;
|
||||||
|
30
src/Symfony/Component/Cache/Tests/Psr16CacheProxyTest.php
Normal file
30
src/Symfony/Component/Cache/Tests/Psr16CacheProxyTest.php
Normal 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());
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user