【问题标题】:Symfony - MemcachedAdapter::__construct() must be an instance of Memcached, string givenSymfony - MemcachedAdapter::__construct() 必须是 Memcached 的实例,给定字符串
【发布时间】:2019-04-04 19:49:28
【问题描述】:

这很奇怪。我使用 Memcached 设置缓存如下:

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

我能够清除终端中的缓存而没有任何错误,但是当我加载我的网站时,我得到以下信息:

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

查看生成的容器类后,我发现:

/**
 * 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'));
}

我不知道它是如何以该字符串作为参数生成的,它应该是 memcached 客户端!

有什么想法吗?无需调试容器类生成,我可以检查什么?

【问题讨论】:

  • 你的 Memcached 类真的没有命名空间吗?诚然,错误信息不匹配。
  • 为什么会这样?这是 PHP Memcached 类
  • 你找到你为什么得到这个了吗?我也有这个问题
  • 嗨,boyd,不确定,我现在签的是不同的合同,所以没有看到这个问题得到解决。也许值得在 github 上添加一个问题? github.com/symfony/symfony/issues
  • 我和你们有同样的错误。任何解决方案都会非常好

标签: php symfony caching memcached autowired


【解决方案1】:

您是否尝试过从 Service-Container 获取 CacheAdapter 而不是在此处创建新实例: return $this->services['cache.app'] = new \Symfony\Component\Cache\Adapter\TraceableAdapter( new \Symfony\Component\Cache\Adapter\MemcachedAdapter('kRTmoLLARw') // new instance? );

【讨论】:

  • 那个容器服务。我将首先向您展示设置容器服务的生成代码。
猜你喜欢
  • 2017-06-12
  • 1970-01-01
  • 2023-03-03
  • 2015-09-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-15
相关资源
最近更新 更多