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

Cache tags are not cached #32712

Copy link
Copy link
Closed
Closed
Copy link
@sbutnariu

Description

@sbutnariu
Issue body actions

Symfony version(s) affected: 4.3.2

Description
When using TagAwareAdapter, the tags attached to an item are not saved in cache, even if the actual items are saved.

How to reproduce
I'm using the following structure:

framework:
    cache:
        app: cache.adapter.redis
        default_redis_provider: "redis://%env(REDIS_CACHE_URL)%"
        pools:
            app.cache.redis.tags:
                adapter: cache.adapter.redis
                provider: cache.default_redis_provider
            app.cache.redis.items:
                adapter: cache.adapter.redis
                provider: cache.default_redis_provider
            app.cache.redis.simple:
                adapter: cache.adapter.redis
                provider: cache.default_redis_provider
services:
    app.cache.redis.taggable:
        class: 'Symfony\Component\Cache\Adapter\TagAwareAdapter'
        arguments:
            - '@app.cache.redis.items'
            - '@app.cache.redis.tags'
    MyAwesomeTaggableRedisCache:
        arguments:
            $adapter: '@app.cache.redis.taggable'

and cache the items with tags attached:

//$this->adapter is app.cache.redis.taggable
$key = 'some_key';
$cachedItem = $this->adapter->getItem($key);
$cachedItem->expiresAfter(600);
$tags=['tag1', 'tag2'];
$cachedItem->tag($tags);
if (false === $cachedItem->isHit()) {
    $result = call_user_func_array($function, $parameters);//get data from db
    $cachedItem->set(serialize($result));
    $this->adapter->save($cachedItem);
}
$result = unserialize($cachedItem->get());
return $result;

Items are correctly cached, and retrieved from cache. However, the tags (in this scenario tag1, tag2) don't seem to be cached, and it's always a miss.
image

If I invalidate by a given tag (eg tag1), then that tag is cached (the items attached to the cached are invalidate a well, so no issue here).
$this->adapter->invalidateTags(['tag1']);
image

From what I saw in the TagAwareAdapter class, this behaviour seems intended (only save tag in cache when invalidating by tag).
My question is: why not cache the tag also when the first item with the given tag is saved?
Possible Solution
Save tag when the first item with the given tag is persisted.

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.