部署后Symfony清除缓存组件

问题描述:

嗨有办法清除所有来自symfony缓存组件的缓存数据?部署后Symfony清除缓存组件

在底部这里http://symfony.com/doc/current/components/cache/cache_pools.html是:(我需要控制台命令)

$cacheIsEmpty = $cache->clear(); 

和命令:

bin/console cache:clear 

保持这种高速缓存不变

我lookig控制台命令巫婆我可以在每个部署中调用* .sh脚本。

EDIT(示例):

默认输入选项:

$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,作曲家安装,bin /控制台缓存:清除...),那么服务器上的新版本仍然有效的缓存(1天),并从中获取数据...

+0

为什么./bin/console缓存:清除不够? – sensorario

+0

问题是更新 - 示例和解释。 –

你可以做任何服务,你想实现Symfony\Component\HttpKernel\CacheClearer\CacheClearerInterface由symfony中使用本地缓存:明确

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(); 
    } 
} 

配置由标签完成kernel.cache_clearer

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'); 
+0

嗨THX回答。我必须添加'使用Symfony \ Component \ Cache \ Adapter \ AdapterInterface;'并在参数中给出'@ cache.app'。但它不起作用 - 没有错误,并且在bin/console cache:clear后仍然有数据从有效缓存中加载 –

+0

如果在clear()方法中放置断点或var_dump(“called”); exit;它被称为? – goto

+0

在控制台我看到'叫'所以是的 –

在结束 - 足以编辑只services.yml并添加:

appbundle.cachecomponent.clearall: 
    class: Symfony\Component\Cache\Adapter\FilesystemAdapter 
    tags: 
     - { name: kernel.cache_clearer } 

我在symfony的新的,所以我希望这是正确的解决方案。