[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 <?php 2 // 3 // Definition of eZCache class 4 // 5 // Created on: <09-Oct-2003 15:24:36 amos> 6 // 7 // SOFTWARE NAME: eZ publish 8 // SOFTWARE RELEASE: 3.9.0 9 // BUILD VERSION: 17785 10 // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS 11 // SOFTWARE LICENSE: GNU General Public License v2.0 12 // NOTICE: > 13 // This program is free software; you can redistribute it and/or 14 // modify it under the terms of version 2.0 of the GNU General 15 // Public License as published by the Free Software Foundation. 16 // 17 // This program is distributed in the hope that it will be useful, 18 // but WITHOUT ANY WARRANTY; without even the implied warranty of 19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 // GNU General Public License for more details. 21 // 22 // You should have received a copy of version 2.0 of the GNU General 23 // Public License along with this program; if not, write to the Free 24 // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 25 // MA 02110-1301, USA. 26 // 27 // 28 29 /*! \file ezcache.php 30 */ 31 32 /*! 33 \class eZCache ezcache.php 34 \brief Main class for dealing with caches in eZ publish. 35 36 Has methods for clearing the various caches according 37 to tag, id or all caches. It also has information for all the caches. 38 39 */ 40 41 include_once ( 'lib/ezfile/classes/ezfilehandler.php' ); 42 include_once ( 'lib/ezfile/classes/ezdir.php' ); 43 include_once ( 'kernel/common/i18n.php' ); 44 45 class eZCache 46 { 47 /*! 48 Constructor 49 */ 50 function eZCache() 51 { 52 } 53 54 /*! 55 \static 56 \return a list of all cache items in the system. 57 */ 58 function fetchList() 59 { 60 $cacheList =& $GLOBALS['eZCacheList']; 61 if ( !isset( $cacheList ) ) 62 { 63 $ini =& eZINI::instance(); 64 $cacheList = array( array( 'name' => ezi18n( 'kernel/cache', 'Content view cache' ), 65 'id' => 'content', 66 'tag' => array( 'content' ), 67 'enabled' => $ini->variable( 'ContentSettings', 'ViewCaching' ) == 'enabled', 68 'path' => $ini->variable( 'ContentSettings', 'CacheDir' ) ), 69 array( 'name' => ezi18n( 'kernel/cache', 'Global INI cache' ), 70 'id' => 'global_ini', 71 'tag' => array( 'ini' ), 72 'enabled' => true, 73 'path' => 'var/cache/ini', 74 'function' => 'eZCacheClearGlobalINI' ), 75 array( 'name' => ezi18n( 'kernel/cache', 'INI cache' ), 76 'id' => 'ini', 77 'tag' => array( 'ini' ), 78 'enabled' => true, 79 'path' => 'ini' ), 80 array( 'name' => ezi18n( 'kernel/cache', 'Codepage cache' ), 81 'id' => 'codepage', 82 'tag' => array( 'codepage' ), 83 'enabled' => true, 84 'path' => 'codepages' ), 85 array( 'name' => ezi18n( 'kernel/cache', 'Expiry cache' ), 86 'id' => 'expiry', 87 'tag' => array( 'content', 'template' ), 88 'enabled' => true, 89 'path' => 'expiry.php' ), 90 array( 'name' => ezi18n( 'kernel/cache', 'Class identifier cache' ), 91 'id' => 'classid', 92 'tag' => array( 'content' ), 93 'enabled' => true, 94 'path' => false, 95 'function' => 'eZCacheClearClassID'), 96 array( 'name' => ezi18n( 'kernel/cache', 'Sort key cache' ), 97 'id' => 'sortkey', 98 'tag' => array( 'content' ), 99 'enabled' => true, 100 'path' => false, 101 'function' => 'eZCacheClearSortKey' ), 102 array( 'name' => ezi18n( 'kernel/cache', 'URL alias cache' ), 103 'id' => 'urlalias', 104 'tag' => array( 'content' ), 105 'enabled' => true, 106 'path' => 'wildcard' ), 107 array( 'name' => ezi18n( 'kernel/cache', 'Character transformation cache' ), 108 'id' => 'chartrans', 109 'tag' => array( 'i18n' ), 110 'enabled' => true, 111 'path' => 'trans' ), 112 array( 'name' => ezi18n( 'kernel/cache', 'Image alias' ), 113 'id' => 'imagealias', 114 'tag' => array( 'image' ), 115 'path' => false, 116 'enabled' => true, 117 'function' => 'eZCacheClearImageAlias' ), 118 array( 'name' => ezi18n( 'kernel/cache', 'Template cache' ), 119 'id' => 'template', 120 'tag' => array( 'template' ), 121 'enabled' => $ini->variable( 'TemplateSettings', 'TemplateCompile' ) == 'enabled', 122 'path' => 'template' ), 123 array( 'name' => ezi18n( 'kernel/cache', 'Template block cache' ), 124 'id' => 'template-block', 125 'tag' => array( 'template', 'content' ), 126 'enabled' => $ini->variable( 'TemplateSettings', 'TemplateCache' ) == 'enabled', 127 'path' => 'template-block', 128 'function' => 'eZCacheClearTemplateBlockCache' ), 129 array( 'name' => ezi18n( 'kernel/cache', 'Template override cache' ), 130 'id' => 'template-override', 131 'tag' => array( 'template' ), 132 'enabled' => true, 133 'path' => 'override' ), 134 array( 'name' => ezi18n( 'kernel/cache', 'RSS cache' ), 135 'id' => 'rss_cache', 136 'tag' => array( 'content' ), 137 'enabled' => true, 138 'path' => 'rss' ), 139 array( 'name' => ezi18n( 'kernel/cache', 'User info cache' ), 140 'id' => 'user_info_cache', 141 'tag' => array( 'user' ), 142 'enabled' => true, 143 'path' => 'user-info' ) 144 ); 145 } 146 return $cacheList; 147 } 148 149 /*! 150 \static 151 Goes through the cache info list \a $cacheInfoList and finds all the unique tags. 152 \return An array with tag strings. 153 \param $cacheInfoList If \c false the list will automatically be fetched, if multiple 154 eZCache functions are called it is a good idea to call 155 fetchList() yourself and pass it as a parameter. 156 */ 157 function fetchTagList( $cacheInfoList = false ) 158 { 159 if ( !$cacheInfoList ) 160 $cacheInfoList = eZCache::fetchList(); 161 162 $tagEntries = array(); 163 foreach ( $cacheInfoList as $cacheInfo ) 164 { 165 $tagList = $cacheInfo['tag']; 166 if ( $tagList !== false ) 167 $tagEntries = array_merge( $tagEntries, $tagList ); 168 } 169 return array_unique( $tagEntries ); 170 } 171 172 /*! 173 \static 174 Goes through the cache info list \a $cacheInfoList and finds all the unique ids. 175 \return An array with id strings. 176 \param $cacheInfoList If \c false the list will automatically be fetched, if multiple 177 eZCache functions are called it is a good idea to call 178 fetchList() yourself and pass it as a parameter. 179 */ 180 function fetchIDList( $cacheInfoList = false ) 181 { 182 if ( !$cacheInfoList ) 183 $cacheInfoList = eZCache::fetchList(); 184 185 $idList = array(); 186 foreach ( $cacheInfoList as $cacheInfo ) 187 { 188 $idList[] = $cacheInfo['id']; 189 } 190 return $idList; 191 } 192 193 /*! 194 \static 195 Finds all cache entries using tag \a $tagName. 196 \return An array with cache items. 197 */ 198 function fetchByTag( $tagName, $cacheInfoList = false ) 199 { 200 if ( !$cacheInfoList ) 201 $cacheInfoList = eZCache::fetchList(); 202 203 $cacheEntries = array(); 204 foreach ( $cacheInfoList as $cacheInfo ) 205 { 206 $tagList = $cacheInfo['tag']; 207 if ( $tagList !== false and in_array( $tagName, $tagList ) ) 208 $cacheEntries[] = $cacheInfo; 209 } 210 return $cacheEntries; 211 } 212 213 /*! 214 \static 215 Finds the first entry with the ID \a $id. 216 \return The cache info structure. 217 */ 218 function fetchByID( $id, $cacheInfoList = false ) 219 { 220 if ( !$cacheInfoList ) 221 $cacheInfoList = eZCache::fetchList(); 222 223 foreach ( $cacheInfoList as $cacheInfo ) 224 { 225 if ( $cacheInfo['id'] == $id ) 226 return $cacheInfo; 227 } 228 return false; 229 } 230 231 /*! 232 \static 233 Finds the entries matching and ID in the list \a $idList. 234 \return An array with cache info structures. 235 */ 236 function fetchByIDList( $idList, $cacheInfoList = false ) 237 { 238 if ( !$cacheInfoList ) 239 $cacheInfoList = eZCache::fetchList(); 240 241 $cacheList = array(); 242 foreach ( $cacheInfoList as $cacheInfo ) 243 { 244 if ( in_array( $cacheInfo['id'], $idList ) ) 245 $cacheList[] = $cacheInfo; 246 } 247 return $cacheList; 248 } 249 250 /*! 251 \static 252 Clears all cache items. 253 */ 254 function clearAll( $cacheList = false ) 255 { 256 if ( !$cacheList ) 257 $cacheList = eZCache::fetchList(); 258 259 foreach ( $cacheList as $cacheItem ) 260 { 261 eZCache::clearItem( $cacheItem ); 262 } 263 return true; 264 } 265 266 /*! 267 \static 268 Finds all cache item which has the tag \a $tagName and clears them. 269 */ 270 function clearByTag( $tagName, $cacheList = false ) 271 { 272 if ( !$cacheList ) 273 $cacheList = eZCache::fetchList(); 274 275 $cacheItems = array(); 276 foreach ( $cacheList as $cacheItem ) 277 { 278 if ( in_array( $tagName, $cacheItem['tag'] ) ) 279 $cacheItems[] = $cacheItem; 280 } 281 foreach ( $cacheItems as $cacheItem ) 282 { 283 eZCache::clearItem( $cacheItem ); 284 } 285 return true; 286 } 287 288 /*! 289 \static 290 Finds all cache item which has ID equal to one of the IDs in \a $idList. 291 You can also submit a single id to \a $idList. 292 */ 293 function clearByID( $idList, $cacheList = false ) 294 { 295 if ( !$cacheList ) 296 $cacheList = eZCache::fetchList(); 297 298 $cacheItems = array(); 299 if ( !is_array( $idList ) ) 300 $idList = array( $idList ); 301 foreach ( $cacheList as $cacheItem ) 302 { 303 if ( in_array( $cacheItem['id'], $idList ) ) 304 $cacheItems[] = $cacheItem; 305 } 306 foreach ( $cacheItems as $cacheItem ) 307 { 308 eZCache::clearItem( $cacheItem ); 309 } 310 return true; 311 } 312 313 /*! 314 \private 315 \static 316 Clears the cache item \a $cacheItem. 317 */ 318 function clearItem( $cacheItem ) 319 { 320 if ( isset( $cacheItem['function'] ) ) 321 { 322 $function= $cacheItem['function']; 323 $function( $cacheItem ); 324 } 325 else 326 { 327 // VS-DBFILE 328 329 $cachePath = eZSys::cacheDirectory() . "/" . $cacheItem['path']; 330 331 switch ( $cacheItem['id'] ) 332 { 333 case 'template-block': 334 case 'expiry': 335 case 'content': 336 case 'urlalias': // wildcard cache 337 case 'rss_cache': 338 case 'user_info_cache': 339 $isContentRelated = true; 340 break; 341 default: 342 $isContentRelated = false; 343 } 344 345 if ( $isContentRelated ) 346 { 347 require_once ( 'kernel/classes/ezclusterfilehandler.php' ); 348 $fileHandler = eZClusterFileHandler::instance(); 349 $fileHandler->fileDelete( $cachePath ); 350 return; 351 } 352 353 if ( is_file( $cachePath ) ) 354 { 355 $handler =& eZFileHandler::instance( false ); 356 $handler->unlink( $cachePath ); 357 } 358 else 359 { 360 eZDir::recursiveDelete( $cachePath ); 361 } 362 } 363 } 364 365 /*! 366 \private 367 Sets the image alias timestamp to the current timestamp, 368 this causes all image aliases to be recreated on viewing. 369 */ 370 function clearImageAlias( $cacheItem ) 371 { 372 include_once ( 'lib/ezutils/classes/ezexpiryhandler.php' ); 373 $expiryHandler = eZExpiryHandler::instance(); 374 $expiryHandler->setTimestamp( 'image-manager-alias', time() ); 375 $expiryHandler->store(); 376 } 377 378 /*! 379 \private 380 Removes all template block cache files and subtree entries. 381 */ 382 function clearTemplateBlockCache( $cacheItem ) 383 { 384 // remove existing cache 385 $cachePath = eZSys::cacheDirectory() . "/" . $cacheItem['path']; 386 387 // VS-DBFILE 388 389 require_once ( 'kernel/classes/ezclusterfilehandler.php' ); 390 $fileHandler = eZClusterFileHandler::instance(); 391 $fileHandler->fileDelete( $cachePath ); 392 393 // remove expiried 'subtree' cache 394 include_once ( 'kernel/classes/ezsubtreecache.php' ); 395 eZSubtreeCache::removeAllExpiryCacheFromDisk(); 396 } 397 398 /*! 399 \private 400 Clears all content class identifier cache files from var/cache. 401 */ 402 function clearClassID( $cacheItem ) 403 { 404 $cachePath = eZSys::cacheDirectory(); 405 406 // VS-DBFILE 407 408 require_once ( 'kernel/classes/ezclusterfilehandler.php' ); 409 $fileHandler = eZClusterFileHandler::instance(); 410 $fileHandler->fileDeleteByRegex( $cachePath, 'class(attribute)?identifiers_.+$' ); 411 } 412 413 /*! 414 \private 415 Clears all datatype sortkey cache files from var/cache. 416 */ 417 function clearSortKey( $cacheItem ) 418 { 419 $cachePath = eZSys::cacheDirectory(); 420 421 // VS-DBFILE 422 423 require_once ( 'kernel/classes/ezclusterfilehandler.php' ); 424 $fileHandler = eZClusterFileHandler::instance(); 425 $fileHandler->fileDeleteByRegex( $cachePath, 'sortkey_.+$' ); 426 } 427 428 /*! 429 \static 430 Clear global ini cache 431 */ 432 function clearGlobalINICache() 433 { 434 eZDir::recursiveDelete( 'var/cache/ini' ); 435 } 436 } 437 438 /*! 439 Helper function for eZCache::clearImageAlias. 440 \note Static functions in classes cannot be used as callback functions in PHP 4, that is why we need this helper. 441 */ 442 function eZCacheClearImageAlias( $cacheItem ) 443 { 444 eZCache::clearImageAlias( $cacheItem ); 445 } 446 447 /*! 448 Helper function for eZCache::clearClassID. 449 \note Static functions in classes cannot be used as callback functions in PHP 4, that is why we need this helper. 450 */ 451 function eZCacheClearClassID( $cacheItem ) 452 { 453 eZCache::clearClassID( $cacheItem ); 454 } 455 456 /*! 457 Helper function for eZCache::clearGlobalINICache. 458 \note Static functions in classes cannot be used as callback functions in PHP 4, that is why we need this helper. 459 */ 460 function eZCacheClearGlobalINI( $cacheItem ) 461 { 462 eZCache::clearGlobalINICache(); 463 } 464 465 466 /*! 467 Helper function for eZCache::clearSortKey. 468 \note Static functions in classes cannot be used as callback functions in PHP 4, that is why we need this helper. 469 */ 470 function eZCacheClearSortKey( $cacheItem ) 471 { 472 eZCache::clearSortKey( $cacheItem ); 473 } 474 475 /*! 476 Helper function for eZCache::clearTemplateBlockCache. 477 \note Static functions in classes cannot be used as callback functions in PHP 4, that is why we need this helper. 478 */ 479 function eZCacheClearTemplateBlockCache( $cacheItem ) 480 { 481 eZCache::clearTemplateBlockCache( $cacheItem ); 482 } 483 484 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |