Search code examples
symfonycachingconfigurationsymfony4

Using RedisTagAwareAdapter in Symfony 4.4


I have an issue getting Symfony to play nicely with a tag-aware adapter for redis

Unfortunately for me, Symfony 5.2 includes this feature, but as we're not switching to a non-lts version that's kind of out of the question. I have tried checking out the configuration, but it does not quite work for me.

Here's my current setup:

# cache.yaml
framework:
  cache:
    prefix_seed: !php/const App\Kernel::APP_VERSION
    app: cache.adapter.redis_tag_aware
  redis.cache_app:
    class: Redis
    factory: ['Symfony\Component\Cache\Adapter\RedisAdapter', 'createConnection']
    arguments:
      - '%env(REDIS_DNS)%'

  cache.adapter.redis_tag_aware:
    class: Symfony\Component\Cache\Adapter\RedisTagAwareAdapter
    arguments:
      $redisClient: '@redis.cache_app'
      $marshaller: '@?cache.default_marshaller'
    calls:
      - ['setLogger', ['@?logger']]
    tags:
      - { name: cache.pool, provider: cache.default_redis_provider, clearer: cache.default_clearer, reset: reset }
      - { name: monolog.logger, channel: cache }

But it screams about argument 0 not existing via some CompilerPass.

Is it not possible to use the App cache as a tagged cache? I suppose I could create a separate pool and maybe use that, but it seems like a weird choice.


Solution

  • Okay so obviously this is a config issue.

    The following will work

    # services.yaml
      redis.cache_app:
        class: Redis
        factory: ['Symfony\Component\Cache\Adapter\RedisAdapter', 'createConnection']
        arguments:
          - '%env(REDIS_DNS)%'
    
      cache.app.redis_tag_aware:
        class: Symfony\Component\Cache\Adapter\RedisTagAwareAdapter
        arguments:
          - '@redis.cache_app'
          - ''
          - 0
          - '@?cache.default_marshaller'
        calls:
          - ['setLogger', ['@?logger']]
        tags:
          - { name: cache.pool, provider: redis.cache_app, clearer: cache.default_clearer, reset: reset }
          - { name: monolog.logger, channel: cache }
    
    # cache.yaml
    framework:
      cache:
        prefix_seed: !php/const App\Kernel::APP_VERSION
        app: cache.app.redis_tag_aware