views:

746

answers:

5

I would like to clear my frontend application's cache from an action in my backend application.

How can I achieve this?

A: 

Google told me that there is a symfony.sh file somewhere and that its argument could be clear-cache frontend. See here

However I don't know Symfony at all.

p4bl0
A: 

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()

AlberT
+2  A: 

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();
bb
A: 

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

Honza Trtik
+2  A: 

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
jeremy