I would like to clear my frontend application's cache from an action in my backend application.
How can I achieve this?
I would like to clear my frontend application's cache from an action in my backend application.
How can I achieve this?
I don't think there is no "clean" way to do the job, as different apps are treated as quite separated environments in symfony. Obviously the job may be done in a less or more dirty way, choose your way to remove any file in the cache/ dir, run the phing task clear-cache (cc) etc ...
you can simply run rm -rf cache/*, but you could break some client request. The simpler thing could be to run symfony cc via passthru() or exec()
This works for me. It removes all cached files from the given directory:
$cache_dir = sfConfig::get('sf_cache_dir').'/'.$app.'/'.$env.'/';
$cache = new sfFileCache(array('cache_dir' => $cache_dir));
$cache->clean();
You can create instance of sfTask and run it like this (in sf 1.2):
$task = new sfCacheClearTask(sfContext::getInstance()->getEventDispatcher(), new sfFormatter());
$arguments = array();
// type can be one of: i18n, routing, template, module, config
$options = array(
'frontend' => 'app',
'routing' => 'type',
'prod' => 'env',
);
$task->run($arguments, $options);
For all possible arguments and options see source code of appropriate sfTask...
I believe the proper way to do this in symfony 1.2 is as follows:
sfContext::switchTo('frontend'); //switch to the environment you wish to clear
sfContext::getInstance()->getViewCacheManager()->getCache()->clean(sfCache::ALL);
sfContext::switchTo('backend'); //switch back to the environment you started from