00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 include_once( 'lib/ezfile/classes/ezfilehandler.php' );
00044 include_once( 'lib/ezfile/classes/ezdir.php' );
00045 include_once( 'kernel/common/i18n.php' );
00046
00047 class eZCache
00048 {
00049
00050
00051
00052 function eZCache()
00053 {
00054 }
00055
00056
00057
00058
00059
00060 function fetchList()
00061 {
00062 $cacheList =& $GLOBALS['eZCacheList'];
00063 if ( !isset( $cacheList ) )
00064 {
00065 $ini =& eZINI::instance();
00066 $cacheList = array( array( 'name' => ezi18n( 'kernel/cache', 'Content view cache' ),
00067 'id' => 'content',
00068 'tag' => array( 'content' ),
00069 'enabled' => $ini->variable( 'ContentSettings', 'ViewCaching' ) == 'enabled',
00070 'path' => $ini->variable( 'ContentSettings', 'CacheDir' ) ),
00071 array( 'name' => ezi18n( 'kernel/cache', 'Global INI cache' ),
00072 'id' => 'global_ini',
00073 'tag' => array( 'ini' ),
00074 'enabled' => true,
00075 'path' => 'var/cache/ini',
00076 'function' => 'eZCacheClearGlobalINI' ),
00077 array( 'name' => ezi18n( 'kernel/cache', 'INI cache' ),
00078 'id' => 'ini',
00079 'tag' => array( 'ini' ),
00080 'enabled' => true,
00081 'path' => 'ini' ),
00082 array( 'name' => ezi18n( 'kernel/cache', 'Codepage cache' ),
00083 'id' => 'codepage',
00084 'tag' => array( 'codepage' ),
00085 'enabled' => true,
00086 'path' => 'codepages' ),
00087 array( 'name' => ezi18n( 'kernel/cache', 'Expiry cache' ),
00088 'id' => 'expiry',
00089 'tag' => array( 'content', 'template' ),
00090 'enabled' => true,
00091 'path' => 'expiry.php' ),
00092 array( 'name' => ezi18n( 'kernel/cache', 'Class identifier cache' ),
00093 'id' => 'classid',
00094 'tag' => array( 'content' ),
00095 'expiry-key' => 'class-identifier-cache',
00096 'enabled' => true,
00097 'path' => false,
00098 'function' => 'eZCacheClearClassID'),
00099 array( 'name' => ezi18n( 'kernel/cache', 'Sort key cache' ),
00100 'id' => 'sortkey',
00101 'tag' => array( 'content' ),
00102 'expiry-key' => 'sort-key-cache',
00103 'enabled' => true,
00104 'path' => false,
00105 'function' => 'eZCacheClearSortKey' ),
00106 array( 'name' => ezi18n( 'kernel/cache', 'URL alias cache' ),
00107 'id' => 'urlalias',
00108 'tag' => array( 'content' ),
00109 'enabled' => true,
00110 'path' => 'wildcard' ),
00111 array( 'name' => ezi18n( 'kernel/cache', 'Character transformation cache' ),
00112 'id' => 'chartrans',
00113 'tag' => array( 'i18n' ),
00114 'enabled' => true,
00115 'path' => 'trans' ),
00116 array( 'name' => ezi18n( 'kernel/cache', 'Image alias' ),
00117 'id' => 'imagealias',
00118 'tag' => array( 'image' ),
00119 'path' => false,
00120 'enabled' => true,
00121 'function' => 'eZCacheClearImageAlias' ),
00122 array( 'name' => ezi18n( 'kernel/cache', 'Template cache' ),
00123 'id' => 'template',
00124 'tag' => array( 'template' ),
00125 'enabled' => $ini->variable( 'TemplateSettings', 'TemplateCompile' ) == 'enabled',
00126 'path' => 'template' ),
00127 array( 'name' => ezi18n( 'kernel/cache', 'Template block cache' ),
00128 'id' => 'template-block',
00129 'tag' => array( 'template', 'content' ),
00130 'enabled' => $ini->variable( 'TemplateSettings', 'TemplateCache' ) == 'enabled',
00131 'path' => 'template-block',
00132 'function' => 'eZCacheClearTemplateBlockCache' ),
00133 array( 'name' => ezi18n( 'kernel/cache', 'Template override cache' ),
00134 'id' => 'template-override',
00135 'tag' => array( 'template' ),
00136 'enabled' => true,
00137 'path' => 'override' ),
00138 array( 'name' => ezi18n( 'kernel/cache', 'RSS cache' ),
00139 'id' => 'rss_cache',
00140 'tag' => array( 'content' ),
00141 'enabled' => true,
00142 'path' => 'rss' ),
00143 array( 'name' => ezi18n( 'kernel/cache', 'User info cache' ),
00144 'id' => 'user_info_cache',
00145 'tag' => array( 'user' ),
00146 'enabled' => true,
00147 'path' => 'user-info' )
00148 );
00149 }
00150 return $cacheList;
00151 }
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 function fetchTagList( $cacheInfoList = false )
00162 {
00163 if ( !$cacheInfoList )
00164 $cacheInfoList = eZCache::fetchList();
00165
00166 $tagEntries = array();
00167 foreach ( $cacheInfoList as $cacheInfo )
00168 {
00169 $tagList = $cacheInfo['tag'];
00170 if ( $tagList !== false )
00171 $tagEntries = array_merge( $tagEntries, $tagList );
00172 }
00173 return array_unique( $tagEntries );
00174 }
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 function fetchIDList( $cacheInfoList = false )
00185 {
00186 if ( !$cacheInfoList )
00187 $cacheInfoList = eZCache::fetchList();
00188
00189 $idList = array();
00190 foreach ( $cacheInfoList as $cacheInfo )
00191 {
00192 $idList[] = $cacheInfo['id'];
00193 }
00194 return $idList;
00195 }
00196
00197
00198
00199
00200
00201
00202 function fetchByTag( $tagName, $cacheInfoList = false )
00203 {
00204 if ( !$cacheInfoList )
00205 $cacheInfoList = eZCache::fetchList();
00206
00207 $cacheEntries = array();
00208 foreach ( $cacheInfoList as $cacheInfo )
00209 {
00210 $tagList = $cacheInfo['tag'];
00211 if ( $tagList !== false and in_array( $tagName, $tagList ) )
00212 $cacheEntries[] = $cacheInfo;
00213 }
00214 return $cacheEntries;
00215 }
00216
00217
00218
00219
00220
00221
00222 function fetchByID( $id, $cacheInfoList = false )
00223 {
00224 if ( !$cacheInfoList )
00225 $cacheInfoList = eZCache::fetchList();
00226
00227 foreach ( $cacheInfoList as $cacheInfo )
00228 {
00229 if ( $cacheInfo['id'] == $id )
00230 return $cacheInfo;
00231 }
00232 return false;
00233 }
00234
00235
00236
00237
00238
00239
00240 function fetchByIDList( $idList, $cacheInfoList = false )
00241 {
00242 if ( !$cacheInfoList )
00243 $cacheInfoList = eZCache::fetchList();
00244
00245 $cacheList = array();
00246 foreach ( $cacheInfoList as $cacheInfo )
00247 {
00248 if ( in_array( $cacheInfo['id'], $idList ) )
00249 $cacheList[] = $cacheInfo;
00250 }
00251 return $cacheList;
00252 }
00253
00254
00255
00256
00257
00258 function clearAll( $cacheList = false )
00259 {
00260 if ( !$cacheList )
00261 $cacheList = eZCache::fetchList();
00262
00263 foreach ( $cacheList as $cacheItem )
00264 {
00265 eZCache::clearItem( $cacheItem );
00266 }
00267 return true;
00268 }
00269
00270
00271
00272
00273
00274 function clearByTag( $tagName, $cacheList = false )
00275 {
00276 if ( !$cacheList )
00277 $cacheList = eZCache::fetchList();
00278
00279 $cacheItems = array();
00280 foreach ( $cacheList as $cacheItem )
00281 {
00282 if ( in_array( $tagName, $cacheItem['tag'] ) )
00283 $cacheItems[] = $cacheItem;
00284 }
00285 foreach ( $cacheItems as $cacheItem )
00286 {
00287 eZCache::clearItem( $cacheItem );
00288 }
00289 return true;
00290 }
00291
00292
00293
00294
00295
00296
00297 function clearByID( $idList, $cacheList = false )
00298 {
00299 if ( !$cacheList )
00300 $cacheList = eZCache::fetchList();
00301
00302 $cacheItems = array();
00303 if ( !is_array( $idList ) )
00304 $idList = array( $idList );
00305 foreach ( $cacheList as $cacheItem )
00306 {
00307 if ( in_array( $cacheItem['id'], $idList ) )
00308 $cacheItems[] = $cacheItem;
00309 }
00310 foreach ( $cacheItems as $cacheItem )
00311 {
00312 eZCache::clearItem( $cacheItem );
00313 }
00314 return true;
00315 }
00316
00317
00318
00319
00320
00321
00322 function clearItem( $cacheItem )
00323 {
00324 if ( isset( $cacheItem['function'] ) )
00325 {
00326 $function= $cacheItem['function'];
00327 $function( $cacheItem );
00328 }
00329 else
00330 {
00331
00332
00333 $cachePath = eZSys::cacheDirectory() . "/" . $cacheItem['path'];
00334
00335 switch ( $cacheItem['id'] )
00336 {
00337 case 'template-block':
00338 case 'expiry':
00339 case 'content':
00340 case 'urlalias':
00341 case 'rss_cache':
00342 case 'user_info_cache':
00343 $isContentRelated = true;
00344 break;
00345 default:
00346 $isContentRelated = false;
00347 }
00348
00349 if ( $isContentRelated )
00350 {
00351 require_once( 'kernel/classes/ezclusterfilehandler.php' );
00352 $fileHandler = eZClusterFileHandler::instance();
00353 $fileHandler->fileDelete( $cachePath );
00354 return;
00355 }
00356
00357 if ( is_file( $cachePath ) )
00358 {
00359 $handler =& eZFileHandler::instance( false );
00360 $handler->unlink( $cachePath );
00361 }
00362 else
00363 {
00364 eZDir::recursiveDelete( $cachePath );
00365 }
00366 }
00367 }
00368
00369
00370
00371
00372
00373
00374 function clearImageAlias( $cacheItem )
00375 {
00376 include_once( 'lib/ezutils/classes/ezexpiryhandler.php' );
00377 $expiryHandler =& eZExpiryHandler::instance();
00378 $expiryHandler->setTimestamp( 'image-manager-alias', time() );
00379 $expiryHandler->store();
00380 }
00381
00382
00383
00384
00385
00386 function clearTemplateBlockCache( $cacheItem )
00387 {
00388
00389 $cachePath = eZSys::cacheDirectory() . "/" . $cacheItem['path'];
00390
00391
00392
00393 require_once( 'kernel/classes/ezclusterfilehandler.php' );
00394 $fileHandler = eZClusterFileHandler::instance();
00395 $fileHandler->fileDelete( $cachePath );
00396
00397
00398 include_once( 'kernel/classes/ezsubtreecache.php' );
00399 eZSubtreeCache::removeAllExpiryCacheFromDisk();
00400 }
00401
00402
00403
00404
00405
00406 function clearClassID( $cacheItem )
00407 {
00408 $cachePath = eZSys::cacheDirectory();
00409
00410
00411
00412 require_once( 'kernel/classes/ezclusterfilehandler.php' );
00413 $fileHandler = eZClusterFileHandler::instance();
00414 $fileHandler->fileDeleteByRegex( $cachePath, 'class(attribute)?identifiers_.+$' );
00415 }
00416
00417
00418
00419
00420
00421 function clearSortKey( $cacheItem )
00422 {
00423 $cachePath = eZSys::cacheDirectory();
00424
00425
00426
00427 require_once( 'kernel/classes/ezclusterfilehandler.php' );
00428 $fileHandler = eZClusterFileHandler::instance();
00429 $fileHandler->fileDeleteByRegex( $cachePath, 'sortkey_.+$' );
00430 }
00431
00432
00433
00434
00435
00436 function clearGlobalINICache()
00437 {
00438 eZDir::recursiveDelete( 'var/cache/ini' );
00439 }
00440 }
00441
00442
00443
00444
00445
00446 function eZCacheClearImageAlias( $cacheItem )
00447 {
00448 eZCache::clearImageAlias( $cacheItem );
00449 }
00450
00451
00452
00453
00454
00455 function eZCacheClearClassID( $cacheItem )
00456 {
00457 eZCache::clearClassID( $cacheItem );
00458 }
00459
00460
00461
00462
00463
00464 function eZCacheClearGlobalINI( $cacheItem )
00465 {
00466 eZCache::clearGlobalINICache();
00467 }
00468
00469
00470
00471
00472
00473
00474 function eZCacheClearSortKey( $cacheItem )
00475 {
00476 eZCache::clearSortKey( $cacheItem );
00477 }
00478
00479
00480
00481
00482
00483 function eZCacheClearTemplateBlockCache( $cacheItem )
00484 {
00485 eZCache::clearTemplateBlockCache( $cacheItem );
00486 }
00487
00488 ?>