2

I'ld like to use the new Symfony 3 Cache Component in a project. I can use it if I define my services by hand like this:

app.cache.adapter.array:
    class: 'Symfony\Component\Cache\Adapter\ArrayAdapter'

app.redis.client:
    class: Predis\Client
    factory:   ['Symfony\Component\Cache\Adapter\RedisAdapter', 'createConnection']
    arguments: ["%redis_dsn%", {timeout: 5}]

app.cache.adapter.redis:
    class: Symfony\Component\Cache\Adapter\RedisAdapter
    abstract: true
    arguments:
        -
        - "api"
        - 0

app.cache.adapter.chain:
    class: 'Symfony\Component\Cache\Adapter\ChainAdapter'
    abstract: true
    arguments:
        - ['@app.cache.adapter.array', "@app.cache.adapter.redis"]
        - 0

cache.api:
    parent: "app.cache.adapter.chain"

But as soon as I use the cache.pool tag or the framework pools configuration to get data in the profiler, I've got an exception

framework:        
    cache:
        pools:
            cache.api:
                adapter: "app.cache.adapter.chain"
                public: true
                default_lifetime: 0
                clearer: ~

And here is the exception

     (1/1) ContextErrorException

Catchable Fatal Error: Argument 1 passed to Symfony\Component\Cache\Adapter\ChainAdapter::__construct() must be of the type array, string given, called in /var/www/julien/htdocs/sccd/website/var/cache/dev/appDevDebugProjectContainer.php on line 4032 and defined
in ChainAdapter.php (line 37)
at ChainAdapter->__construct('+FJMe7Pj5l', 0)in appDevDebugProjectContainer.php (line 4032)
at appDevDebugProjectContainer->getCache_Api_RecorderInnerService()in appDevDebugProjectContainer.php (line 623)
at appDevDebugProjectContainer->getCache_ApiService()in classes.php (line 3292)
at Container->get('cache.api')in appDevDebugProjectContainer.php (line 2629)

Can anyone help me on this ?

I'm using the Symfony v3.3.11, and predis/predis v1.1.1 for redis connection.

Thanks

Mait'
  • 98
  • 8
  • Not an answer, but just a suggestion: you can use FQCN's as a service name: https://symfony.com/doc/current/service_container.html#service-parameters. – Stephan Vierkant Nov 13 '17 at 18:16
  • I could do this only if autowiring was activated. As it's a project I upgraded from 2.8 to 3.3, I didn't configure autowiring for now. – Mait' Nov 14 '17 at 19:48
  • I also had this problem, i tried to create a cache pool that uses PDOAdapter. I would consider this a bug in the framework bundle since i found no way via frameworkBundle, only via service. – ivoba Oct 05 '18 at 09:18

0 Answers0