我正在尝试在我的环境中使用不同的缓存系统。我想要,例如,Filesystem
for dev and memcached
for prod.
我在用交响乐3.3.10.
为了实现这一点,我想自动装配缓存接口如下:
use Psr\SimpleCache\CacheInterface;
class Api {
public function __construct(CacheInterface $cache)
{
$this->cache = $cache;
}
}
这是我的配置文件:
配置_dev.yml:
framework:
cache:
app: cache.adapter.filesystem
配置产品.yml:
framework:
cache:
app: cache.adapter.memcached
...
Here is the error I get:
当文件系统缓存被声明为服务:
services:
Symfony\Component\Cache\Simple\FilesystemCache: ~
但现在我不能有另一个缓存系统test环境喜欢空缓存。事实上,我只需声明一项服务继承自缓存接口。这是不可能的配置测试正在使用配置开发 too.
这是开始服务.yml如果有帮助:
services:
_defaults:
autowire: true
autoconfigure: true
public: false
关于如何根据环境自动连接不同的缓存系统有什么想法吗?
EDIT:
这是工作配置:
use Psr\Cache\CacheItemPoolInterface;
class MyApi
{
/**
* @var CacheItemPoolInterface
*/
private $cache;
public function __construct(CacheItemPoolInterface $cache)
{
$this->cache = $cache;
}
}
配置.yml:
framework:
# ...
cache:
pools:
app.cache.api:
default_lifetime: 3600
服务.yml:
# ...
Psr\Cache\CacheItemPoolInterface:
alias: 'app.cache.api'