Closed
Closed
Copy link
Description
Symfony version(s) affected: 4.4.11
Description
TagAwareAdapter::invalidateTags() was not working when it was wrapped ArrayAdapter.
How to reproduce
public function testInvalidateTagsByTagAwareAdapterWrappedArrayAdapter()
{
$cache = new TagAwareAdapter(new ArrayAdapter());
$item = $cache->getItem('foo');
$item->set(1);
$item->tag('bar');
$cache->save($item);
$this->assertSame(1, $cache->getItem('foo')->get());
$this->assertSame(true, $cache->invalidateTags(['bar']));
$this->assertSame(null, $cache->getItem('foo')->get()); // This code should be pass, but failed.
}
Possible Solution
I think that the cause of this issue is due to the following factors:
- TagAwareAdapter will store "{tag}\0tag\0" cache item with expiry = 0.
- ArrayAdaputer::save() does not treat expiry = 0 as indefinite(=PHP_INT_MAX).
line 127: if (null !== $expiry && $expiry <= microtime(true)) {
line 140: $this->expiries[$key] = null !== $expiry ? $expiry : PHP_INT_MAX;
So i think possible solution is ArrayAdaputer::save() treat expiry = 0 as indefinite.