Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Closed
@rain-noise

Description

@rain-noise
Issue body actions

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.