Clearing Symfony cache for another application

后端 未结 5 2255
不知归路
不知归路 2021-02-10 05:37

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

How can I achieve this?

相关标签:
5条回答
  • 2021-02-10 06:06

    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
    
    0 讨论(0)
  • 2021-02-10 06:10

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

    0 讨论(0)
  • 2021-02-10 06:16

    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();
    
    0 讨论(0)
  • 2021-02-10 06:26

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

    0 讨论(0)
  • 2021-02-10 06:30

    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');
    
    0 讨论(0)
提交回复
热议问题