[ Index ] |
|
Code source de SPIP Agora 1.4 |
1 <?php 2 /***************************************************** 3 * This file is part of Agora, web based content management system. 4 * 5 * Agora is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; version 2 of the License. 8 * 9 * Agora is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details (file "COPYING"). 13 * 14 * Copyright © Arnaud Martin, Antoine Pitrou et Philippe Rivière. 15 * List of authors detailed in "copyright_fr.html" file. 16 * E-mail : agora@sig.premier-ministre.gouv.fr 17 * Web site : http://www.agora.gouv.fr 18 *****************************************************/ 19 // Base class for Agora CACHE. 20 // 21 if (defined("_AGORA_CACHE")) 22 return; 23 24 define("_AGORA_CACHE", "1"); 25 26 require_once("Cache/Function.php"); 27 28 /** 29 * AgoraCache is a class for article cache. 30 * @package Cache 31 * @author Erwan Le Bescond <elebescond@clever-age.com> 32 * @author Olivier Mansour <omansour@clever-age.com> 33 * @access public 34 */ 35 36 class AgoraCache { 37 38 // {{{ properties 39 40 /** 41 * Parameters instance used for PEAR::CACHE factory and Metier subclasses factories. 42 * 43 * @access private 44 */ 45 var $_cacheParameters; 46 47 var $_objectId; 48 49 var $_objectType; 50 51 var $_cacheId; 52 53 var $_groupId; 54 55 var $_cache; // objet PEAR CaCHE 56 57 var $_objectMetier; 58 59 // }}} 60 61 // {{{ getCacheParameters() 62 63 /** 64 * Getter method to retreive the instance Parameters object 65 * 66 * @return Cache parameters 67 * @access public 68 */ 69 70 function getCacheParameters () { 71 return $this->_cacheParameters; 72 } 73 74 // }}} 75 76 // {{{ setCacheParameters() 77 78 /** 79 * Setter method to set the instance Parameters object 80 * 81 * @param $cacheParameters new Cache parameters 82 */ 83 84 function setCacheParameters ($cacheParameters) { 85 if (get_class($cacheParameters) == "CacheParameters") { 86 $this->_cacheParameters = $cacheParameters; 87 } 88 else { 89 return PEAR::raiseError( 90 "Erreur! le parametre de la methode setCacheParameters doit etre un objet de la hierarchie CacheParameters !", 91 null, 92 null, 93 null, 94 null, 95 null, 96 false); 97 } 98 } 99 100 // }}} 101 102 // {{{ constructor 103 104 /** 105 * AgoraCache constructor. 106 * 107 * @access public 108 */ 109 110 function AgoraCache ($cacheParams) { 111 //var_dump($cacheParams); 112 //require_once "Cache.php"; 113 $this->_cache = new Cache($cacheParams->getContainerType(), $cacheParams->getOptions()); 114 $this->_cacheParameters = $cacheParams; 115 116 // activation du FileLocking pour le container file 117 if ($cacheParams->getContainerType() == 'file') { 118 $this->_cache->_fileLocking = true; 119 } 120 } 121 122 // }}} 123 124 // {{ 125 126 function getCacheId ($options = '') { 127 return $this->_cache->generateID($options); 128 } 129 130 // }} 131 132 // {{ 133 134 function getCacheGroupId () { 135 return $this->_objectType . '-' . $this->_objectId; 136 //return $this->_objectType; 137 138 } 139 140 // }} 141 142 // {{ 143 144 function getCacheGeneralGroupId () { 145 return $this->_objectType; 146 } 147 148 // }} 149 150 // {{ 151 152 function cacheExist ($cacheId) { 153 $isExpired = $this->_cache->isExpired($cacheId, $this->getCacheGroupId()); 154 $isCached = $this->_cache->isCached($cacheId, $this->getCacheGroupId()); 155 return (!$isExpired AND $isCached); 156 } 157 158 // }} 159 160 // {{ 161 162 function generalCacheExist ($cacheId) { 163 //echo '<br />cache id: '.$cacheId; 164 $isExpired = $this->_cache->isExpired($cacheId, $this->getCacheGeneralGroupId()); 165 $isCached = $this->_cache->isCached($cacheId, $this->getCacheGeneralGroupId()); 166 return (!$isExpired AND $isCached); 167 } 168 169 // }} 170 171 // {{ 172 173 function saveCache ($cacheId, $data) { 174 return $this->_cache->save($cacheId, $data, $this->_cacheParameters->getTTL(), $this->getCacheGroupId()); 175 } 176 177 // }} 178 179 // {{ 180 181 function saveGeneralCache ($cacheId, $data) { 182 return $this->_cache->save($cacheId, $data, $this->_cacheParameters->getTTL(), $this->getCacheGeneralGroupId()); 183 } 184 185 // }} 186 187 // {{ 188 189 function loadCache ($cacheId) { 190 $data = $this->_cache->load($cacheId, $this->getCacheGroupId()); 191 return $data; 192 } 193 194 // }} 195 196 // {{ 197 198 function loadGeneralCache ($cacheId) { 199 $data = $this->_cache->load($cacheId, $this->getCacheGeneralGroupId()); 200 return $data; 201 } 202 203 // }} 204 205 // {{ 206 207 function removeCache ($cacheId) { 208 $this->_cache->remove($cacheId, $this->getCacheGroupId()); 209 } 210 211 // }} 212 213 // {{ 214 215 function removeGeneralCache ($cacheId) { 216 $this->_cache->remove($cacheId, $this->getCacheGeneralGroupId()); 217 } 218 219 // }} 220 221 // {{ 222 223 function flushCache () { 224 @$this->_cache->flush($this->getCacheGroupId()); 225 // @ solution pourrie : mais le cache n'est pas forcement present donc il risque d'y avoir une remontee d erreur 226 227 } 228 229 // }} 230 231 // {{ 232 233 function flushGeneralCache () { 234 @$this->_cache->flush($this->getCacheGeneralGroupId()); 235 } 236 237 // }} 238 239 // {{ 240 241 function flushBothCache () { 242 //echo 'flush des caches'; 243 @$this->flushCache(); 244 @$this->flushGeneralCache(); 245 } 246 247 // }} 248 249 // {{ 250 251 /** 252 * purge tout le cache 253 **/ 254 255 function flushAllCache () { 256 @$this->_cache->flush(); 257 } 258 259 // }} 260 261 } 262 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 14:40:03 2007 | par Balluche grâce à PHPXref 0.7 |