Skip to content

[Cache] Error when using cache chain as adapter #35119

Closed
@Nyholm

Description

@Nyholm

Symfony version(s) affected: 4.4.x and 5.0.x

Description
When using a cache chain as an adapter we get an error when building the container.

How to reproduce

framework:
    cache:
        app: cache.chain
        pools:
            cache.chain:
                adapters:
                    - cache.adapter.array
                    - cache.adapter.apcu


            doctrine.result_cache_pool:
                adapter: cache.app

When warming up the cache we will get:

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Symfony\Component\DependencyInjection\ChildDefinition::__construct() must be of the type string, object given, called in /project/vendor/symfony/cache/DependencyInjection/CachePoolPass.php on line 106 and defined in /project/vendor/symfony/dependency-injection/ChildDefinition.php:30
Stack trace:
#0 /project/vendor/symfony/cache/DependencyInjection/CachePoolPass.php(106): Symfony\Component\DependencyInjection\ChildDefinition->__construct(Object(Symfony\Component\DependencyInjection\ChildDefinition))
#1 /project/vendor/symfony/dependency-injection/Compiler/Compiler.php(91): Symfony\Component\Cache\DependencyInjection\CachePoolPass->process(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
#2 /project/vendor/symfony/dependency-injection/ContainerBuilder.php(734): Symfony\Component\Dependency in /project/vendor/symfony/dependency-injection/ChildDefinition.php on line 30

Possible Solution

I have no possible solution at the moment.

Additional context

This could happen if you define your cache chain as cache.app (which I believe you should). Then other cache pools like the ones used by Doctrine will complain. A workaround is to tell doctrine to use another (non-chain) cache pool.

# config/packages/prod/doctrine.yaml
# ...
framework:
    cache:
        pools:
            doctrine.result_cache_pool:
                adapter: cache.redis_pool
            doctrine.system_cache_pool:
                adapter: cache.system

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