dpsq8476 2019-08-14 10:34
浏览 111
已采纳

Symfony 4.3,标签:redis缓存池的true选项不实现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.

  • 写回答

1条回答 默认 最新

  • drodsh7940 2019-08-15 23:41
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 simulink中怎么使用solve函数?
  • ¥30 dspbuilder中使用signalcompiler时报错Error during compilation: Fitter failed,求解决办法
  • ¥15 gwas 分析-数据质控之过滤稀有突变中出现的问题
  • ¥15 没有注册类 (异常来自 HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
  • ¥15 知识蒸馏实战博客问题
  • ¥15 用PLC设计纸袋糊底机送料系统
  • ¥15 simulink仿真中dtc控制永磁同步电机如何控制开关频率
  • ¥15 用C语言输入方程怎么
  • ¥15 网站显示不安全连接问题
  • ¥15 51单片机显示器问题