Symfony - MemcachedAdapter::__construct() must be an instance of Memcached, string given

本小妞迷上赌 提交于 2019-12-11 04:43:05

问题


This is rather bizarre. I have set up caching with Memcached as follows:

framework.yaml

framework:
    cache:
        app: app.memcached_adapter

services.yaml

app.memcached_client:
    class: Memcached
    factory: 'Symfony\Component\Cache\Adapter\MemcachedAdapter::createConnection'
    arguments: [['%app.memcached.dsn.1%', '%app.memcached.dsn.2%']]
    public: true

app.memcached_adapter:
    class: Symfony\Component\Cache\Adapter\MemcachedAdapter
    arguments:
        - '@app.memcached_client'
    public: true

I am able to clear cache in the terminal without any errors, but when I load my site, I get the following:

Type error: Argument 1 passed to Symfony\Component\Cache\Adapter\MemcachedAdapter::__construct() 
must be an instance of Memcached, string given, called in 
/users/me/project/please-dont-mention-the-company/sports/var/cache/lcl/ContainerXqbuh45/srcLclDebugProjectContainer.php 
on line 1029

Upon looking in said generated container class, I found this:

/**
 * Gets the public 'cache.app' shared service.
 *
 * @return \Symfony\Component\Cache\Adapter\TraceableAdapter
 */
protected function getCache_AppService()
{
    return $this->services['cache.app'] = new \Symfony\Component\Cache\Adapter\TraceableAdapter(new \Symfony\Component\Cache\Adapter\MemcachedAdapter('kRTmoLLARw'));
}

I have no idea how it generated with that string as the argument, it should be the memcached client!

Any ideas? Anything I can check without having to debug the container class generation?


回答1:


have you tried it to get the CacheAdapter from the Service-Container instead of creating a new Instance here: return $this->services['cache.app'] = new \Symfony\Component\Cache\Adapter\TraceableAdapter( new \Symfony\Component\Cache\Adapter\MemcachedAdapter('kRTmoLLARw') // new instance? );



来源:https://stackoverflow.com/questions/53086855/symfony-memcachedadapter-construct-must-be-an-instance-of-memcached-stri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!