phpsymfony4redis-cache

Symfony 4.3, tags:true option for redis cache pool does not implement TagAware ItemInterface


Using symfony 4.3, I have configured a cache pool that should enable TagAwarable for caching items. The configuration is like so:

framework:
cache:
    #app: cache.adapter.redis
    default_redis_provider: 'redis://%env(REDIS_HOST)%:%env(int:REDIS_PORT)%'

    pools:
        redis.cache:
            adapter: '%framework_cache_adapter%'
            provider: 'redis://%env(REDIS_HOST)%:%env(int:REDIS_PORT)%'
            default_lifetime: '%framework_cache_lifetime%'
            tags: true

In the code, using Dependency Injection I retrieve the CacheInterface using the pool name and trying to tag it which throws the following exception:

Cache item "appSettings" comes from a non tag-aware pool: you cannot tag it.

The code looks like this:

public function __construct(EntityManagerInterface $em, CacheInterface $redisCache)
{
    $this->m_cache = $redisCache;
    $this->m_entityManage = $em;
}

public function getKey(string $key) : ?string
{
    $appSettings = $this->m_cache->get(self::CACHE_KEY, function (ItemInterface $item) {
        $item->expiresAfter(3600);
        $item->tag([ 'settings', 'app_cache' ]);

        return $settings;
    });

    return $appSettings[$key] ?? null;
}

I have tried differernt methods to no avail and do not know how to proceed from here.

Any help is appreciated how to make the item be tagged.


Solution

  • I had come across same problem.
    Using \Symfony\Contracts\Cache\TagAwareCacheInterface fixed it for me.

    EDIT
    See https://github.com/symfony/symfony/issues/33201 for more info.