Symfony-MemcachedAdapter :: __ construct()必须是Memcached的实例,给定字符串 [英] Symfony - MemcachedAdapter::__construct() must be an instance of Memcached, string given
问题描述
这很奇怪.我已经使用Memcached设置了缓存,如下所示:
This is rather bizarre. I have set up caching with Memcached as follows:
framework.yaml
framework.yaml
framework:
cache:
app: app.memcached_adapter
services.yaml
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?
推荐答案
您尝试过从服务容器中获取CacheAdapter而不是在此处创建新实例的方法:
return $this->services['cache.app'] = new \Symfony\Component\Cache\Adapter\TraceableAdapter(
new \Symfony\Component\Cache\Adapter\MemcachedAdapter('kRTmoLLARw') // new instance?
);
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?
);
这篇关于Symfony-MemcachedAdapter :: __ construct()必须是Memcached的实例,给定字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!