[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 /** 3 * Translation table cache. 4 * @author Wei Zhuo <weizhuo[at]gmail[dot]com> 5 * @version $Id: sfMessageCache.class.php 2834 2006-11-27 14:09:05Z fabien $ 6 * @package symfony 7 * @subpackage i18n 8 */ 9 10 /** 11 * Cache the translation table into the file system. 12 * It can cache each cataloug+variant or just the whole section. 13 * 14 * @package System.I18N.core 15 * @author $Author: weizhuo $ 16 * @version $Id: sfMessageCache.class.php 2834 2006-11-27 14:09:05Z fabien $ 17 */ 18 class sfMessageCache 19 { 20 /** 21 * Cache Lite instance. 22 * 23 * @var TCache_Lite 24 */ 25 protected $cache; 26 27 /** 28 * Cache life time, default is 1 year. 29 */ 30 protected $lifetime = 3153600; 31 32 /** 33 * Create a new Translation cache. 34 * 35 * @param string $cacheDir Directory to store the cache files. 36 */ 37 public function initialize($options = array()) 38 { 39 $this->cache = new sfFileCache(); 40 $this->cache->initialize($options); 41 } 42 43 /** 44 * Get the cache life time. 45 * 46 * @return int Cache life time. 47 */ 48 public function getLifeTime() 49 { 50 return $this->lifetime; 51 } 52 53 /** 54 * Set the cache life time. 55 * 56 * @param int $time Cache life time. 57 */ 58 public function setLifeTime($time) 59 { 60 $this->lifetime = intval($time); 61 } 62 63 /** 64 * Get the cache file ID based section and locale. 65 * 66 * @param string $catalogue The translation section. 67 * @param string $culture The translation locale, e.g. "en_AU". 68 */ 69 protected function getID($catalogue, $culture) 70 { 71 return $culture; 72 } 73 74 /** 75 * Get the cache file GROUP based section and locale. 76 * 77 * @param string $catalogue The translation section. 78 * @param string $culture The translation locale, e.g. "en_AU". 79 */ 80 protected function getGroup($catalogue, $culture) 81 { 82 return $catalogue; 83 } 84 85 /** 86 * Get the data from the cache. 87 * 88 * @param string $catalogue The translation section. 89 * @param string $culture The translation locale, e.g. "en_AU". 90 * @param string $filename If the source is a file, this file's modified time is newer than the cache's modified time, no cache hit. 91 * @return mixed Boolean FALSE if no cache hit. Otherwise, translation 92 * table data for the specified section and locale. 93 */ 94 public function get($catalogue, $culture, $lastmodified = 0) 95 { 96 $ID = $this->getID($catalogue, $culture); 97 $group = $this->getGroup($catalogue, $culture); 98 99 if ($lastmodified <= 0 || $lastmodified > $this->cache->lastModified($ID, $group)) 100 { 101 return false; 102 } 103 104 return unserialize($this->cache->get($ID, $group)); 105 } 106 107 /** 108 * Save the data to cache for the specified section and locale. 109 * 110 * @param array $data The data to save. 111 * @param string $catalogue The translation section. 112 * @param string $culture The translation locale, e.g. "en_AU". 113 */ 114 public function save($data, $catalogue, $culture) 115 { 116 $ID = $this->getID($catalogue, $culture); 117 $group = $this->getGroup($catalogue, $culture); 118 119 return $this->cache->set($ID, $group, serialize($data)); 120 } 121 122 /** 123 * Clean up the cache for the specified section and locale. 124 * 125 * @param string $catalogue The translation section. 126 * @param string $culture The translation locale, e.g. "en_AU". 127 */ 128 public function clean($catalogue, $culture) 129 { 130 $group = $this->getGroup($catalogue, $culture); 131 $this->cache->clean($group); 132 } 133 134 /** 135 * Flush the cache. Deletes all the cache files. 136 */ 137 public function clear() 138 { 139 $this->cache->clean(); 140 } 141 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |