简体   繁体   中英

Symfony2 http_cache in custom location

In Symfony2, the command for clearing cache ...

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

removes completely the app/cache/prod folder. I'd like to preserve the content of http_cache. Is there any way to tell Symfony2 to store the http_cache in other location not affected when do a cache:clear?

For example, there is a simple configuration in config.yml to move sessions out of cache folder, in order to not clear all user sessions on every deployment.

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

Is there some similar way to do this with http_cache folder?

In AppCache.php you can use createStore method.

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 of that function looks like that:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM