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
< 8B4D button data-component="IconButton" type="button" class="prc-Button-ButtonBase-c50BI prc-Button-IconButton-szpyj" data-loading="false" data-no-visuals="true" data-size="medium" data-variant="invisible" aria-describedby=":R1ri56b:-loading-announcement" aria-labelledby=":R3i56b:">
Closed
@rain-noise

Description

@rain-noise

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

      0