*/ // WBClass::load('patTemplate_TemplateCache_File'); WBClass::load('patI18n'); /** * patTemplate TemplateCache Wombat * * Extends template cache File and add funcionality to check current locale settings * * @package wombat * @author gERD Schaufelberger */ class patTemplate_TemplateCache_Wombat extends patTemplate_TemplateCache { /** * Load Template from Cache * * @param string cache key * @param integer modification time of original template * @return array|boolean either an array containing the templates or false cache could not be loaded */ public function load($key, $modTime = -1) { if (1 > WBParam::get('wb/cache/use', 1)) { return false; } $filename = $this->getCachefileName($key); if (!file_exists($filename) || !is_readable($filename)) { return false; } $generatedOn = filemtime($filename); $ttl = $this->getParam('lifetime'); if ($ttl == 'auto') { if ($modTime < 1) { return false; } if ($modTime > $generatedOn) { return false; } return unserialize(file_get_contents($filename)); } if (!is_int($ttl)) { return false; } if ($generatedOn + $ttl < time()) { return false; } return unserialize( file_get_contents( $filename ) ); } /** * Write Template to Cache * * @param string cache key * @param array templates to store * @return boolean true on success */ public function write($key, $templates) { if (1 > WBParam::get('wb/cache/use', 1)) { return true; } $cacheFile = $this->getCachefileName($key); $fp = @fopen($cacheFile, 'w'); if (!$fp) { return false; } flock($fp, LOCK_EX); fputs($fp, serialize($templates)); flock($fp, LOCK_UN); $filemode = $this->getParam('filemode'); if (null !== $filemode && false !== $filemode) { chmod($cacheFile, $filemode); } return true; } /** * get the cache filename * * @param string cache key * @return string cache file name */ protected function getCachefileName($key) { return sprintf( '%s/%s%s-%s.cache' , $this->getParam('cacheFolder') , $this->getParam('prefix') , patI18n::getLocale(patI18n::LOCALE_TYPE_LANG) , $key); } }