Caching Symfony在部署后清除缓存组件
嗨,有没有办法从symfony缓存组件中清除所有缓存数据 下面是:(我需要控制台命令) 指挥部:Caching Symfony在部署后清除缓存组件,caching,deployment,components,symfony,Caching,Deployment,Components,Symfony,嗨,有没有办法从symfony缓存组件中清除所有缓存数据 下面是:(我需要控制台命令) 指挥部: bin/console cache:clear 保持此缓存未被触及 我正在寻找控制台命令,我可以在每次部署时调用*.sh脚本 编辑(示例): 默认输入选项: $cache = new FilesystemAdapter(); $defaultInputOptions = $cache->getItem('mainFilter.defaultInputOptions'); if (!$
bin/console cache:clear
保持此缓存未被触及
我正在寻找控制台命令,我可以在每次部署时调用*.sh脚本
编辑(示例):
默认输入选项:
$cache = new FilesystemAdapter();
$defaultInputOptions = $cache->getItem('mainFilter.defaultInputOptions');
if (!$defaultInputOptions->isHit()) {
// collect data, format etc.
$expiration = new \DateInterval('P1D');
$defaultInputOptions->expiresAfter($expiration);
$cache->save($defaultInputOptions);
} else {
return $defaultInputOptions->get();
}
但若我在我的机器上更改了“收集数据、格式等”中的某些内容,然后进行部署(git pull、composer安装、bin/console缓存:clear…),那个么服务器上的新版本仍然具有有效缓存(1天)并从中获取数据…您可以让任何您想要的服务实现Symfony本机使用的
Symfony\Component\HttpKernel\cacheClear\cacheClearInterface
use Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface;
use Symfony\Component\Cache\Adapter\AdapterInterface;
final class SomeCacheClearer implements CacheClearerInterface
{
private $cache;
public function __construct(AdapterInterface $filesystemAdapter)
{
$this->cache = $filesystemAdapter;
}
public function clear($cacheDir)
{
$this->cache->clear();
}
}
通过标记内核进行配置。缓存\u
cache_provider.clearer:
class: AppBundle\Path\SomeCacheClearer
arguments:
- 'my_app_cache'
tags:
- { name: kernel.cache_clearer }
编辑:关于缓存作为服务的精度:
您的缓存服务可以这样定义
my_app_cache:
class: Symfony\Component\Cache\Adapter\FilesystemAdapter
或者如果要指定名称空间和ttl
my_app_cache:
class: Symfony\Component\Cache\Adapter\FilesystemAdapter
arguments:
- 'my_cache_namespace'
- 30 #cache ttl (in seconds)
所以你应该不要使用
$cache = new FilesystemAdapter();
但随着服务注入
$cache = $this->get('my_app_cache');
最后-仅编辑
services.yml
并添加以下内容即可:
appbundle.cachecomponent.clearall:
class: Symfony\Component\Cache\Adapter\FilesystemAdapter
tags:
- { name: kernel.cache_clearer }
我是symfony的新手,所以我希望这是正确的解决方案。为什么。/bin/控制台缓存:清除是不够的?问题是更新-示例和解释。您好,谢谢回答。我必须添加
使用Symfony\Component\Cache\Adapter\AdapterInterface
和in参数给出@cache.app
。但它不起作用-无错误且在bin/console缓存之后:如果放置断点或var_转储(“调用”),则清除有效缓存中的
静态数据加载;退出代码>在方法clear()中,它被调用了吗?在控制台中,我看到'called',所以是的,谢谢。它在service.yaml中没有任何参数。
appbundle.cachecomponent.clearall:
class: Symfony\Component\Cache\Adapter\FilesystemAdapter
tags:
- { name: kernel.cache_clearer }