8000 TagAwareAdapter::invalidateTags() was not working when it was wrapped ArrayAdapter · Issue #37950 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

TagAwareAdapter::invalidateTags() was not working when it was wrapped ArrayAdapter #37950

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rain-noise opened this issue Aug 26, 2020 · 1 comment

Comments

@rain-noise
Copy link

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:

  1. TagAwareAdapter will store "{tag}\0tag\0" cache item with expiry = 0.
  2. 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.

@nicolas-grekas
Copy link
Member

Thanks for the report. I'm closing as duplicate of #37667, fixed in #37671, to be released soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
0