0
votes

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?

1
this is not the case @zalex, this documentation shows how to override the whole cache directory, but I want only to override http_cache subdirectory. Pawel response is right.jonaguera
my mistake, sorry, didn't understand question.zalex

1 Answers

1
votes

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