【问题标题】:Symfony2 http_cache in custom locationSymfony2 http_cache 在自定义位置
【发布时间】:2016-07-21 14:16:53
【问题描述】:

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

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

完全删除 app/cache/prod 文件夹。我想保留 http_cache 的内容。有什么方法可以告诉 Symfony2 将 http_cache 存储在其他不受缓存影响的位置:清除?

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

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

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

【问题讨论】:

  • @zalex 不是这种情况,该文档显示了如何覆盖整个缓存目录,但我只想覆盖 http_cache 子目录。帕维尔的反应是正确的。
  • 我的错误,抱歉,没看懂问题。

标签: php symfony caching


【解决方案1】:

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
    }
}

Default content 的那个函数看起来像这样:

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

【讨论】:

  • 太棒了,这成功了!! return new Symfony\Component\HttpKernel\HttpCache\Store ($this->rootDir ?: $this->kernel->getRootDir().'/var/http_cache');
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-18
  • 2016-10-17
  • 2013-09-20
相关资源
最近更新 更多