bug #38156 [Cache] fix ProxyAdapter not persisting items with infinite expiration (dmaicher)

This PR was merged into the 4.4 branch.

Discussion
----------

[Cache] fix ProxyAdapter not persisting items with infinite expiration

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #38066
| License       | MIT
| Doc PR        | -

Commits
-------

d3af877022 [Cache] fix ProxyAdapter not persisting items with infinite expiration
This commit is contained in:
Nicolas Grekas 2020-09-11 13:34:06 +02:00
commit ac188871c2
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