Clearing Symfony cache for another application

纵饮孤独 提交于 2019-12-03 08:18:30

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

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

If anyone is looking for clearing one cache item (one page):

sfContext::switchTo('frontend');
sfContext::getInstance()->getViewCacheManager()->remove("module/action?&param1=value1&param2=value2","THE-DOMAIN-OF-YOUR-FRONTEND-APPLICATION-IF-U-USE-IT-IN-CACHE-KEYS");
sfContext::switchTo('backend');

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!