自定义位置中的Symfony2 http_cache


Symfony2 http_cache in custom location

在Symfony2中,清除缓存的命令。。。

  php app/console cache:clear --env=prod

完全删除app/cache/prod文件夹。我想保留http_cache的内容。是否有任何方法可以告诉Symfony2在执行缓存时将http_cache存储在不受影响的其他位置:clear?

例如,config.yml中有一个简单的配置,可以将会话从缓存文件夹中移出,从而不清除每次部署中的所有用户会话。

framework:
[...]
session:
    save_path: %kernel.root_dir%/var/sessions

对于http_cache文件夹,有类似的方法吗?

AppCache.php中,可以使用createStore方法。

require_once __DIR__.'/AppKernel.php';
use Symfony'Bundle'FrameworkBundle'HttpCache'HttpCache;
class AppCache extends HttpCache
{
    protected function createStore()
    {
        // Use custom logic to build the store
    }
}

该功能的默认内容如下:

protected function createStore()
{
    return new Store($this->cacheDir ?: $this->kernel->getCacheDir().'/http_cache');
}