Skip to content

[CACHE] Never hits cache with TagAwareAdapter #54097

@AtCliffUnderline

Description

@AtCliffUnderline

Symfony version(s) affected

6.4.4

Description

A bit similar to #53825

As in the code below, there is fetching several keys with mget. Keys are already exists in database. First fetch of keys with mget retrieves them all and create good $bufferedItems.

But after that getTagVersion gets wrong tag (screenshot) and unseting them all (TagAwareAdapter.php:191). This bad tag have been stored by this adapter.
image

And after unset them all it creates items with hit: false.

How to reproduce

$cache = new TagAwareAdapter(
    new ChainAdapter(
        [
            new ArrayAdapter(300, false, 300),
            new RedisTagAwareAdapter(
                $this->redisConnectionPoolService->getClientByPoolName('cache'),
                'redis.tag.aware.symfony1',
                86400,
                new DefaultMarshaller(false),
            ),
        ],
        300,
    ),
);

$keys = ['key1', 'key2', 'key3'];
$tag = 'some_tag';
$notHitItems = [];
$items = $cache->getItems($keys);
foreach ($items as $item) {
    if (! $item->isHit() || ! is_array($item->get())) {
        $notHitItems[] = $item;
    }
}

foreach ($notHitItems as $item) {
    $item->set(['some_value']);
    $item->expiresAfter(3 * 24 * 60 * 60);
    $item->tag($tag);

    $cache->saveDeferred($item);
}

if (! empty($notHitItems)) {
    $cache->commit();
}

Possible Solution

No response

Additional Context

Chain adapter is not really needed here. But this is my production setup.
Seems kinda critical imho

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy