[Cache] fix ProxyAdapter not persisting items with infinite expiration

This commit is contained in:
David Maicher 2020-09-04 20:10:14 +02:00 committed by Nicolas Grekas
parent afd4027c11
commit d3af877022
2 changed files with 24 additions and 1 deletions

View File

@ -88,7 +88,7 @@ class ProxyAdapter implements AdapterInterface, CacheInterface, PruneableInterfa
$item["\0*\0value"] = ["\x9D".pack('VN', (int) (0.1 + $metadata[self::METADATA_EXPIRY] - self::METADATA_EXPIRY_OFFSET), $metadata[self::METADATA_CTIME])."\x5F" => $item["\0*\0value"]];
}
$innerItem->set($item["\0*\0value"]);
$innerItem->expiresAt(null !== $item["\0*\0expiry"] ? \DateTime::createFromFormat('U.u', sprintf('%.6f', $item["\0*\0expiry"])) : null);
$innerItem->expiresAt(null !== $item["\0*\0expiry"] ? \DateTime::createFromFormat('U.u', sprintf('%.6f', 0 === $item["\0*\0expiry"] ? \PHP_INT_MAX : $item["\0*\0expiry"])) : null);
},
null,
CacheItem::class

View File

@ -24,6 +24,29 @@ class TagAwareAndProxyAdapterIntegrationTest extends TestCase
$cache->save($item);
$this->assertSame('bar', $cache->getItem('foo')->get());
$cache->invalidateTags(['tag2']);
$this->assertFalse($cache->getItem('foo')->isHit());
}
public function testIntegrationUsingProxiedAdapterForTagsPool()
{
$arrayAdapter = new ArrayAdapter();
$cache = new TagAwareAdapter($arrayAdapter, new ProxyAdapter($arrayAdapter));
$item = $cache->getItem('foo');
$item->expiresAfter(600);
$item->tag(['baz']);
$item->set('bar');
$cache->save($item);
$this->assertSame('bar', $cache->getItem('foo')->get());
$this->assertTrue($cache->getItem('foo')->isHit());
$cache->invalidateTags(['baz']);
$this->assertFalse($cache->getItem('foo')->isHit());
}
public function dataProvider(): array