Skip to content

Tag invalidation doesn't seem to work across requests anymore #27149

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
harmbandstra opened this issue May 4, 2018 · 3 comments
Closed

Tag invalidation doesn't seem to work across requests anymore #27149

harmbandstra opened this issue May 4, 2018 · 3 comments

Comments

@harmbandstra
Copy link

Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 4.0.9

There was a change in the TagAwareAdapter from version 4.0.8 to 4.0.9 which seems to break the tag invalidation. I included a unit test which runs fine with version 4.0.8 of the cache component but breaks with version 4.0.9.

Expected behavior (this is how it works in 4.0.8)

  • Get cache key "item1" (isHit == false)
  • Write a cache key "item1" with "tag1"
  • Get cache key (isHit == true)
  • Invalidate tag "tag1"
  • Get cache key (isHit == false)
  • Now get the key in a new request, simulated by $tagAwareAdapter2 = new TagAwareAdapter), and get will result in a isHit == false.

Actual behavior (right now in 4.0.9)

  • Get cache key "item1" (isHit == false)
  • Write a cache key "item1" with "tag1"
  • Get cache key (isHit == true)
  • Invalidate tag "tag1"
  • Get cache key (isHit == false)
  • Now get the key in a new request, simulated by $tagAwareAdapter2 = new TagAwareAdapter), and get will result in a isHit == true.

You can use this unit test to reproduce

<?php

namespace App\Tests;

use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\TagAwareAdapter;

class TagCacheTest extends KernelTestCase
{
    const ITEM = 'item1';
    const TAG = 'tag1';

    public function testInvalidateTags()
    {
        $tagAwareAdapter1 = new TagAwareAdapter(new FilesystemAdapter('', 0));
        $tagAwareAdapter1->clear();

        $cacheItem1 = $tagAwareAdapter1->getItem(self::ITEM);
        $this->assertFalse($cacheItem1->isHit(), 'Item should not have been hit (1)');

        $cacheItem1->tag([self::TAG]);
        $cacheItem1->set('this is the value of [' . self::ITEM . ']');

        $saved = $tagAwareAdapter1->save($cacheItem1);
        $this->assertTrue($saved);

        $cacheItem2 = $tagAwareAdapter1->getItem(self::ITEM);
        $this->assertTrue($cacheItem2->isHit(), 'Item should have been hit');

        $success = $tagAwareAdapter1->invalidateTags([self::TAG]);
        $this->assertTrue($success);

        $cacheItem3 = $tagAwareAdapter1->getItem(self::ITEM);
        $this->assertFalse($cacheItem3->isHit(), 'Item should not have been hit (2)');

        $tagAwareAdapter2 = new TagAwareAdapter(new FilesystemAdapter('', 0));
        $cacheItem4 = $tagAwareAdapter2->getItem(self::ITEM);
        $this->assertFalse($cacheItem4->isHit(), 'Item should not have been hit (3)');
    }
}
@xabbuh
Copy link
Member

xabbuh commented May 4, 2018

That's the same as #27147, right?

@harmbandstra
Copy link
Author

@xabbuh Looks like it, yeah. It apparently took me 20 minutes to create this bug report ;-)

@xabbuh
Copy link
Member

xabbuh commented May 4, 2018

no problem :) I am closing in favour of #27147 then

@xabbuh xabbuh closed this as completed May 4, 2018
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