Neu blog
Simple cache management class for Symfony
Submitted by ryan on Mon, 21/07/2008 - 15:49
<?php class nbCacheManager { static $cache_dirs = array(); /** * @desc Clears partial cache files * @access public * @param mixed - leave blank for ALL partials * @param string - application * @return void * @author Ryan Johnson * @version */ static public function clearPartialCache($partial_path = array(), $app = 'public') { $partial_paths = is_array($partial_path) ? $partial_path : array($partial_path); foreach($partial_paths as $path) { $path = str_replace('/', '/_', $path); self::$cache_dirs[] = sprintf('/%s/*/template/*/all/sf_cache_partial/%s', $app, $path ); } self::doClearCache(); } /** * @desc Clears global cache * @access public * @param string - leave blank for ALL partials * @param string - application * @return void * @author Ryan Johnson * @version */ static public function clearCache($path = array(), $app ='public') { $paths = is_array($path) ? $path : array($path); foreach($paths as $path) { self::$cache_dirs[] = sprintf('/%s/*/template/*/all/%s', $app, $path); } self::doClearCache(); } /** * @desc executes the clear * @access public * @param void * @return void * @author Ryan Johnson * @version */ static private function doClearCache() { foreach(self::$cache_dirs as $cache_dir) { sfToolkit::clearGlob( sfConfig::get('sf_root_cache_dir') ); } } /** * @desc clears all template cache * @access public * @param string - application * @return void * @author Ryan Johnson * @version */ static public function clearTemplateCache($app ='public') { self::$cache_dirs = array(sprintf('/%s/*/template/*/all', $app)); self::doClearCache(); } } ?>
I've used in at the end of the admin generator save method, so that everytime a record is saved in the backend the template cache is cleared
protected function saveMyModule($my_module) { $my_module->save(); nbCacheManager::clearTemplateCache(); }
CONTACT US
- 1300 858 495
- +61 2 8011 8238
- Suite 202, 8 Clarke street Crows Nest, NSW 2065, Australia
- View Google map
Web design
Engaging websites and digital experiences that deliver ease of use with fresh, contemporary design.
Web development
Custom built PHP business applications including CMS, CRM, customer databases and third-party software integration.
Web marketing
Exposing business to a global audience through SEO, adwords, email marketing and banner advertising.