eZ Publish  [trunk]
ezcache.php
Go to the documentation of this file.
00001 <?php
00002 /**
00003  * File containing the {@link eZCache} class
00004  *
00005  * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved.
00006  * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
00007  * @version //autogentag//
00008  * @package kernel
00009  */
00010 
00011 /**
00012  * eZCache ezcache.php
00013  *
00014  * Main class for dealing with caches in eZ Publish.
00015  *
00016  * Has methods for clearing the various caches according
00017  * to tag, id or all caches. It also has information for all the caches.
00018  *
00019  * @package kernel
00020  */
00021 class eZCache
00022 {
00023     /**
00024      * Return a list of all cache items in the system.
00025      *
00026      * @return array The list of cache items
00027      */
00028     static function fetchList()
00029     {
00030         static $cacheList = null;
00031         if ( $cacheList === null )
00032         {
00033             $ini = eZINI::instance();
00034             $textToImageIni = eZINI::instance( 'texttoimage.ini' );
00035             $cacheList = array( array( 'name' => ezpI18n::tr( 'kernel/cache', 'Content view cache' ),
00036                                        'id' => 'content',
00037                                        'is-clustered' => true,
00038                                        'tag' => array( 'content' ),
00039                                        'expiry-key' => 'content-view-cache',
00040                                        'enabled' => $ini->variable( 'ContentSettings', 'ViewCaching' ) == 'enabled',
00041                                        'path' => $ini->variable( 'ContentSettings', 'CacheDir' ),
00042                                        'function' => array( 'eZCache', 'clearContentCache' ) ),
00043                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'Global INI cache' ),
00044                                        'id' => 'global_ini',
00045                                        'tag' => array( 'ini' ),
00046                                        'enabled' => true,
00047                                        'path' => 'var/cache/ini',
00048                                        'function' => array( 'eZCache', 'clearGlobalINICache' ),
00049                                        'purge-function' => array( 'eZCache', 'clearGlobalINICache' ) ),
00050                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'INI cache' ),
00051                                        'id' => 'ini',
00052                                        'tag' => array( 'ini' ),
00053                                        'enabled' => true,
00054                                        'path' => 'ini' ),
00055                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'Codepage cache' ),
00056                                        'id' => 'codepage',
00057                                        'tag' => array( 'codepage' ),
00058                                        'enabled' => true,
00059                                        'path' => 'codepages' ),
00060 /* Entry is disabled since it does not make sense to remove it, it is not a cache file.
00061                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'Expiry cache' ),
00062                                        'id' => 'expiry',
00063                                        'tag' => array( 'content', 'template' ),
00064                                        'enabled' => true,
00065                                        'path' => 'expiry.php',
00066                                        'function' => array( 'eZCache', 'clearExpiry' ) ),*/
00067                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'Class identifier cache' ),
00068                                        'id' => 'classid',
00069                                        'tag' => array( 'content' ),
00070                                        'expiry-key' => 'class-identifier-cache',
00071                                        'enabled' => true,
00072                                        'path' => false,
00073                                        'is-clustered' => true,
00074                                        'function' => array( 'eZCache', 'clearClassID' ),
00075                                        'purge-function' => array( 'eZCache', 'clearClassID' ) ),
00076                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'Sort key cache' ),
00077                                        'id' => 'sortkey',
00078                                        'tag' => array( 'content' ),
00079                                        'expiry-key' => 'sort-key-cache',
00080                                        'enabled' => true,
00081                                        'path' => false,
00082                                        'function' => array( 'eZCache', 'clearSortKey' ),
00083                                        'purge-function' => array( 'eZCache', 'clearSortKey' ),
00084                                        'is-clustered' => true ),
00085                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'URL alias cache' ),
00086                                        'id' => 'urlalias',
00087                                        'is-clustered' => true,
00088                                        'tag' => array( 'content' ),
00089                                        'enabled' => true,
00090                                        'path' => 'wildcard' ),
00091                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'Character transformation cache' ),
00092                                        'id' => 'chartrans',
00093                                        'tag' => array( 'i18n' ),
00094                                        'enabled' => true,
00095                                        'path' => 'trans' ),
00096                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'Image alias' ),
00097                                        'id' => 'imagealias',
00098                                        'tag' => array( 'image' ),
00099                                        'path' => false,
00100                                        'enabled' => true,
00101                                        'function' => array( 'eZCache', 'clearImageAlias' ),
00102                                        'purge-function' => array( 'eZCache', 'purgeImageAlias' ),
00103                                        'is-clustered' => true ),
00104                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'Template cache' ),
00105                                        'id' => 'template',
00106                                        'tag' => array( 'template' ),
00107                                        'enabled' => $ini->variable( 'TemplateSettings', 'TemplateCompile' ) == 'enabled',
00108                                        'path' => 'template' ),
00109                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'Template block cache' ),
00110                                        'id' => 'template-block',
00111                                        'is-clustered' => true,
00112                                        'tag' => array( 'template', 'content' ),
00113                                        'expiry-key' => 'global-template-block-cache',
00114                                        'enabled' => $ini->variable( 'TemplateSettings', 'TemplateCache' ) == 'enabled',
00115                                        'path' => 'template-block',
00116                                        'function' => array( 'eZCache', 'clearTemplateBlockCache' ) ),
00117                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'Template override cache' ),
00118                                        'id' => 'template-override',
00119                                        'tag' => array( 'template' ),
00120                                        'enabled' => true,
00121                                        'path' => 'override',
00122                                        'function' => array( 'eZCache', 'clearTemplateOverrideCache' ) ),
00123                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'Text to image cache' ),
00124                                        'id' => 'texttoimage',
00125                                        'tag' => array( 'template' ),
00126                                        'enabled' => $textToImageIni->variable( 'ImageSettings', 'UseCache' ) == 'enabled',
00127                                        'path' => $textToImageIni->variable( 'PathSettings', 'CacheDir' ),
00128                                        'function' => array( 'eZCache', 'clearTextToImageCache' ),
00129                                        'purge-function' => array( 'eZCache', 'purgeTextToImageCache' ),
00130                                        'is-clustered' => true ),
00131                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'RSS cache' ),
00132                                        'id' => 'rss_cache',
00133                                        'is-clustered' => true,
00134                                        'tag' => array( 'content' ),
00135                                        'enabled' => true,
00136                                        'path' => 'rss' ),
00137                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'User info cache' ),
00138                                        'id' => 'user_info_cache',
00139                                        'is-clustered' => true,
00140                                        'tag' => array( 'user' ),
00141                                        'expiry-key' => 'user-info-cache',
00142                                        'enabled' => true,
00143                                        'path' => 'user-info',
00144                                        'function' => array( 'eZCache', 'clearUserInfoCache' ) ),
00145                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'Content tree menu (browser cache)' ),
00146                                        'id' => 'content_tree_menu',
00147                                        'tag' => array( 'content' ),
00148                                        'path' => false,
00149                                        'enabled' => true,
00150                                        'function' => array( 'eZCache', 'clearContentTreeMenu' ),
00151                                        'purge-function' => array( 'eZCache', 'clearContentTreeMenu' ) ),
00152                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'State limitations cache' ),
00153                                        'is-clustered' => true,
00154                                        'id' => 'state_limitations',
00155                                        'tag' => array( 'content' ),
00156                                        'expiry-key' => 'state-limitations',
00157                                        'enabled' => true,
00158                                        'path' => false,
00159                                        'function' => array( 'eZCache', 'clearStateLimitations' ),
00160                                        'purge-function' => array( 'eZCache', 'clearStateLimitations' ) ),
00161                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'Design base cache' ),
00162                                        'id' => 'design_base',
00163                                        'tag' => array( 'template' ),
00164                                        'enabled' => $ini->variable( 'DesignSettings', 'DesignLocationCache' ) == 'enabled',
00165                                        'path' => false,
00166                                        'function' => array( 'eZCache', 'clearDesignBaseCache' ),
00167                                        'purge-function' => array( 'eZCache', 'clearDesignBaseCache' ) ),
00168                                 /**
00169                                  * caches the list of active extensions (per siteaccess and global)
00170                                  * @see eZExtension::activeExtensions()
00171                                  */
00172                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'Active extensions cache' ),
00173                                        'id' => 'active_extensions',
00174                                        'tag' => array( 'ini' ),
00175                                        'expiry-key' => 'active-extensions-cache',
00176                                        'enabled' => true,
00177                                        'path' => false,
00178                                        'function' => array( 'eZCache', 'clearActiveExtensions' ),
00179                                        'purge-function' => array( 'eZCache', 'clearActiveExtensions' ) ),
00180 
00181                                 array( 'name' => ezpI18n::tr( 'kernel/cache', 'TS Translation cache' ),
00182                                        'id' => 'translation',
00183                                        'tag' => array( 'i18n' ),
00184                                        'enabled' => true,
00185                                        'expiry-key' => 'ts-translation-cache',
00186                                        'path' => 'translation',
00187                                        'function' => array( 'eZCache', 'clearTSTranslationCache' )
00188                                 ),
00189             );
00190 
00191             // Append cache items defined (in ini) by extensions, see site.ini[Cache] for details
00192             foreach ( $ini->variable( 'Cache', 'CacheItems' ) as $cacheItemKey )
00193             {
00194                 $name = 'Cache_' . $cacheItemKey;
00195                 if ( !$ini->hasSection( $name ) )
00196                 {
00197                     eZDebug::writeWarning( "Missing site.ini section: '$name', skipping!", __METHOD__ );
00198                     continue;
00199                 }
00200 
00201                 $cacheItem = array();
00202                 if ( $ini->hasVariable( $name, 'name' ) )
00203                     $cacheItem['name'] = $ini->variable( $name, 'name' );
00204                 else
00205                     $cacheItem['name'] = ucwords( $cacheItemKey );
00206 
00207                 if ( $ini->hasVariable( $name, 'id' ) )
00208                     $cacheItem['id'] = $ini->variable( $name, 'id' );
00209                 else
00210                     $cacheItem['id'] = $cacheItemKey;
00211 
00212                 if ( $ini->hasVariable( $name, 'isClustered' ) )
00213                     $cacheItem['is-clustered'] = $ini->variable( $name, 'isClustered' );
00214                 else
00215                     $cacheItem['is-clustered'] = false;
00216 
00217                 if ( $ini->hasVariable( $name, 'tags' ) )
00218                     $cacheItem['tag'] = $ini->variable( $name, 'tags' );
00219                 else
00220                     $cacheItem['tag'] = array();
00221 
00222                 if ( $ini->hasVariable( $name, 'expiryKey' ) )
00223                     $cacheItem['expiry-key'] = $ini->variable( $name, 'expiryKey' );
00224 
00225                 if ( $ini->hasVariable( $name, 'enabled' ) )
00226                     $cacheItem['enabled'] = $ini->variable( $name, 'enabled' );
00227                 else
00228                     $cacheItem['enabled'] = true;
00229 
00230                 if ( $ini->hasVariable( $name, 'path' ) )
00231                     $cacheItem['path'] = $ini->variable( $name, 'path' );
00232                 else
00233                     $cacheItem['path'] = false;
00234 
00235                 if ( $ini->hasVariable( $name, 'class' ) )
00236                     $cacheItem['function'] = array( $ini->variable( $name, 'class' ), 'clearCache' );
00237 
00238                 if ( $ini->hasVariable( $name, 'purgeClass' ) )
00239                     $cacheItem['purge-function'] = array( $ini->variable( $name, 'purgeClass' ), 'purgeCache' );
00240 
00241                 $cacheList[] = $cacheItem;
00242             }
00243         }
00244         return $cacheList;
00245     }
00246 
00247     /**
00248      * Goes through the cache info list $cacheInfoList and finds all the unique tags.
00249      *
00250      * @param bool|array $cacheInfoList If false the list will automatically be fetched, if multiple
00251      * eZCache functions are called it is a good idea to call fetchList() yourself and pass it as a parameter.
00252      *
00253      * @return array An array with tag strings.
00254      */
00255     static function fetchTagList( $cacheInfoList = false )
00256     {
00257         if ( !$cacheInfoList )
00258             $cacheInfoList = eZCache::fetchList();
00259 
00260         $tagEntries = array();
00261         foreach ( $cacheInfoList as $cacheInfo )
00262         {
00263             $tagList = $cacheInfo['tag'];
00264             if ( $tagList !== false )
00265                 $tagEntries = array_merge( $tagEntries, $tagList );
00266         }
00267         return array_unique( $tagEntries );
00268     }
00269 
00270     /**
00271      * Goes through the cache info list $cacheInfoList and finds all the unique ids.
00272      *
00273      * @param bool|array $cacheInfoList If false the list will automatically be fetched, if multiple
00274      * eZCache functions are called it is a good idea to call fetchList() yourself and pass it as a parameter.
00275      *
00276      * @return array An array with id strings.
00277      */
00278     static function fetchIDList( $cacheInfoList = false )
00279     {
00280         if ( !$cacheInfoList )
00281             $cacheInfoList = eZCache::fetchList();
00282 
00283         $idList = array();
00284         foreach ( $cacheInfoList as $cacheInfo )
00285         {
00286             $idList[] = $cacheInfo['id'];
00287         }
00288         return $idList;
00289     }
00290 
00291     /**
00292      * Finds all cache entries using tag $tagName.
00293      *
00294      * @param string $tagName The tag name
00295      * @param bool|array $cacheInfoList The list of cache info per entry
00296      * @return array An array with cache items.
00297      */
00298     static function fetchByTag( $tagName, $cacheInfoList = false )
00299     {
00300         if ( !$cacheInfoList )
00301             $cacheInfoList = eZCache::fetchList();
00302 
00303         $cacheEntries = array();
00304         foreach ( $cacheInfoList as $cacheInfo )
00305         {
00306             $tagList = $cacheInfo['tag'];
00307             if ( $tagList !== false and in_array( $tagName, $tagList ) )
00308                 $cacheEntries[] = $cacheInfo;
00309         }
00310         return $cacheEntries;
00311     }
00312 
00313     /**
00314      * Finds the first entry with the ID $id.
00315      *
00316      * @param string $id The entry id.
00317      * @param array|bool The list of cache info per entry
00318      * @return array The cache info structure.
00319      */
00320     static function fetchByID( $id, $cacheInfoList = false )
00321     {
00322         if ( !$cacheInfoList )
00323             $cacheInfoList = eZCache::fetchList();
00324 
00325         foreach ( $cacheInfoList as $cacheInfo )
00326         {
00327             if ( $cacheInfo['id'] == $id )
00328                 return $cacheInfo;
00329         }
00330         return false;
00331     }
00332 
00333     /**
00334      * Finds the entries matching and ID in the list \a $idList.
00335      *
00336      * @param array $idList The list of cache ID
00337      * @param array|bool The list of cache info per entry
00338      * @return array An array with cache info structures.
00339      */
00340     static function fetchByIDList( $idList, $cacheInfoList = false )
00341     {
00342         if ( !$cacheInfoList )
00343             $cacheInfoList = eZCache::fetchList();
00344 
00345         $cacheList = array();
00346         foreach ( $cacheInfoList as $cacheInfo )
00347         {
00348             if ( in_array( $cacheInfo['id'], $idList ) )
00349                 $cacheList[] = $cacheInfo;
00350         }
00351         return $cacheList;
00352     }
00353 
00354     /**
00355      * Clears all cache items.
00356      *
00357      * @param bool $cacheList
00358      * @return bool True
00359      */
00360     static function clearAll( $cacheList = false )
00361     {
00362         if ( !$cacheList )
00363             $cacheList = eZCache::fetchList();
00364 
00365         foreach ( $cacheList as $cacheItem )
00366         {
00367             eZCache::clearItem( $cacheItem );
00368         }
00369         return true;
00370     }
00371 
00372     /**
00373      * Finds all cache item which has the tag \a $tagName and clears them.
00374      *
00375      * @param string $tagName The tag name
00376      * @param bool|array $cacheList The list of caches, default false
00377      */
00378     static function clearByTag( $tagName, $cacheList = false )
00379     {
00380         if ( !$cacheList )
00381             $cacheList = eZCache::fetchList();
00382 
00383         $cacheItems = array();
00384         foreach ( $cacheList as $cacheItem )
00385         {
00386             if ( in_array( $tagName, $cacheItem['tag'] ) )
00387                 $cacheItems[] = $cacheItem;
00388         }
00389         foreach ( $cacheItems as $cacheItem )
00390         {
00391             eZCache::clearItem( $cacheItem );
00392         }
00393         return true;
00394     }
00395 
00396     /**
00397      * Finds all cache item which has ID equal to one of the IDs in $idList.
00398      * You can also submit a single id to $idList.
00399      *
00400      * @param array $idList The cache ID list
00401      * @param bool|array $cacheList The list of caches, default false
00402      */
00403     static function clearByID( $idList, $cacheList = false )
00404     {
00405         if ( !$cacheList )
00406             $cacheList = eZCache::fetchList();
00407 
00408         $cacheItems = array();
00409         if ( !is_array( $idList ) )
00410             $idList = array( $idList );
00411         foreach ( $cacheList as $cacheItem )
00412         {
00413             if ( in_array( $cacheItem['id'], $idList ) )
00414                 $cacheItems[] = $cacheItem;
00415         }
00416         foreach ( $cacheItems as $cacheItem )
00417         {
00418             eZCache::clearItem( $cacheItem );
00419         }
00420         return true;
00421     }
00422 
00423     /**
00424      *
00425      * Clears or purges the cache item $cacheItem.
00426      *
00427      * If $purge is true then the system will ensure the entries are removed from
00428      * local storage or database backend, otherwise it will use possible optimizations
00429      * which might only invalidate the cache entry directly or use global expiry values.
00430      *
00431      * @param $cacheItem Cache item array taken from fetchList()
00432      * @param $purge     Controls whether clearing/invalidation or purge is used.
00433      * @param $reporter  Callback which is called when the system has purged files from the system, called with filename and purge count as parameters.
00434      * @param $iterationSleep The amount of microseconds to sleep between each purge iteration, false means no sleep.
00435      * @param $iterationMax   The maximum number of items to purge in one iteration, false means use default limit.
00436      * @param $expiry         A timestamp which is matched against all cache items, if the modification of the cache is older than the expiry the cache is purged, false means no expiry checking.
00437      */
00438     static function clearItem( $cacheItem, $purge = false, $reporter = false, $iterationSleep = false, $iterationMax = false, $expiry = false )
00439     {
00440         // Get the global expiry value if one is set and compare it with supplied $expiry value.
00441         // Use the largest value of the two.
00442         if ( isset( $cacheItem['expiry-key'] ) )
00443         {
00444             $key = $cacheItem['expiry-key'];
00445             eZExpiryHandler::registerShutdownFunction();
00446             $expiryHandler = eZExpiryHandler::instance();
00447             $keyValue = $expiryHandler->getTimestamp( $key );
00448             if ( $keyValue !== false )
00449             {
00450                 if ( $expiry !== false )
00451                     $expiry = max( $expiry, $keyValue );
00452                 else
00453                     $expiry = $keyValue;
00454             }
00455         }
00456 
00457         $cacheItem['purge']          = $purge;
00458         $cacheItem['reporter']       = $reporter;
00459         $cacheItem['iterationSleep'] = $iterationSleep;
00460         $cacheItem['iterationMax']   = $iterationMax;
00461         $cacheItem['expiry']         = $expiry;
00462         $functionName = false;
00463         if ( $purge && isset( $cacheItem['purge-function'] ) )
00464             $functionName = 'purge-function';
00465         else if ( !$purge && isset( $cacheItem['function'] ) )
00466             $functionName = 'function';
00467         if ( $functionName )
00468         {
00469             $function = $cacheItem[$functionName];
00470             if ( is_callable( $function ) )
00471                 call_user_func_array( $function, array( $cacheItem ) );
00472             else
00473                 eZDebug::writeError("Could not call cache item $functionName for id '$cacheItem[id]', is it a static public function?", __METHOD__ );
00474         }
00475         else
00476         {
00477             if ( !isset( $cacheItem['path'] ) || strlen( $cacheItem['path'] ) < 1 )
00478             {
00479                 eZDebug::writeError( "No path specified for cache item '$cacheItem[name]', can not clear cache.", __METHOD__ );
00480                 return;
00481             }
00482 
00483             $cachePath = eZSys::cacheDirectory() . "/" . $cacheItem['path'];
00484 
00485             if ( isset( $cacheItem['is-clustered'] ) )
00486                 $isClustered = $cacheItem['is-clustered'];
00487             else
00488                 $isClustered = false;
00489 
00490             if ( $isClustered )
00491             {
00492                 $fileHandler = eZClusterFileHandler::instance( $cachePath );
00493                 if ( $purge )
00494                     $fileHandler->purge( $reporter, $iterationSleep, $iterationMax, $expiry );
00495                 else
00496                     $fileHandler->delete();
00497                 return;
00498             }
00499 
00500             if ( is_file( $cachePath ) )
00501             {
00502                 $handler = eZFileHandler::instance( false );
00503                 $handler->unlink( $cachePath );
00504             }
00505             else
00506             {
00507                 eZDir::recursiveDelete( $cachePath );
00508             }
00509         }
00510     }
00511 
00512     /**
00513      * Sets the image alias timestamp to the current timestamp,
00514      * this causes all image aliases to be recreated on viewing.
00515      */
00516     static function clearImageAlias( $cacheItem )
00517     {
00518         eZExpiryHandler::registerShutdownFunction();
00519         $expiryHandler = eZExpiryHandler::instance();
00520         $expiryHandler->setTimestamp( 'image-manager-alias', time() );
00521         $expiryHandler->store();
00522     }
00523 
00524     /**
00525      * Purges the image aliases of all ezimage attribute. The original image is
00526      * kept.
00527      *
00528      * @param array $cacheItem
00529      * @access public
00530      */
00531     static function purgeImageAlias( $cacheItem )
00532     {
00533         // 1. fetch ezcontentclass having an ezimage attribute
00534         // 2. fetch objects of these classes
00535         // 3. purge image alias for all version
00536 
00537         $imageContentClassAttributes = eZContentClassAttribute::fetchList(
00538             true,
00539             array(
00540                 'data_type' => 'ezimage',
00541                 'version' => eZContentClass::VERSION_STATUS_DEFINED
00542             )
00543         );
00544         $classIds = array();
00545         $attributeIdentifiersByClass = array();
00546         foreach ( $imageContentClassAttributes as $ccAttr )
00547         {
00548             $identifier = $ccAttr->attribute( 'identifier' );
00549             $ccId = $ccAttr->attribute( 'contentclass_id' );
00550             if ( !isset( $attributeIdentifiersByClass[$ccId] ) )
00551             {
00552                 $attributeIdentifiersByClass[$ccId] = array();
00553             }
00554             $attributeIdentifiersByClass[$ccId][] = $identifier;
00555             $classIds[] = $ccId;
00556 
00557         }
00558 
00559         $subTreeParams = array(
00560             'ClassFilterType' => 'include',
00561             'ClassFilterArray' => $classIds,
00562             'MainNodeOnly' => true,
00563             'IgnoreVisibility' => true,
00564             'LoadDataMap' => false,
00565             'Limit' => 100,
00566             'Offset' => 0
00567         );
00568         $count = 0;
00569         while ( true )
00570         {
00571             $nodes = eZContentObjectTreeNode::subTreeByNodeID( $subTreeParams, 1 );
00572             if ( empty( $nodes ) )
00573             {
00574                 break;
00575             }
00576             foreach ( $nodes as $node )
00577             {
00578                 call_user_func( $cacheItem['reporter'], '', $count );
00579                 $object = $node->attribute( 'object' );
00580                 self::purgeImageAliasForObject(
00581                     $cacheItem, $object, $attributeIdentifiersByClass[$object->attribute( 'contentclass_id' )]
00582                 );
00583                 $count++;
00584             }
00585             eZContentObject::clearCache();
00586             $subTreeParams['Offset'] += $subTreeParams['Limit'];
00587         }
00588         self::clearImageAlias( $cacheItem );
00589     }
00590 
00591     /**
00592      * The purge the image aliases in all versions of the content object.
00593      *
00594      * @param array $cacheItem
00595      * @param eZContentObject $object
00596      * @param array $imageIdentifiers array of ezimage attribute identifiers
00597      */
00598     private static function purgeImageAliasForObject( array $cacheItem, eZContentObject $object, array $imageIdentifiers )
00599     {
00600         $versions = $object->attribute( 'versions' );
00601         foreach ( $versions as $version )
00602         {
00603             $dataMap = $version->attribute( 'data_map' );
00604             foreach ( $imageIdentifiers as $identifier )
00605             {
00606                 $attr = $dataMap[$identifier];
00607                 if ( !$attr instanceof eZContentObjectAttribute )
00608                 {
00609                     eZDebug::writeError( "Missing attribute $identifier in object " . $object->attribute( 'id' ) . ", version " . $version->attribute( 'version' ) . ". This indicates data corruption.", __METHOD__ );
00610                 }
00611                 elseif ( $attr->attribute( 'has_content' ) )
00612                 {
00613                     $attr->attribute( 'content' )->purgeAllAliases( $attr );
00614                 }
00615             }
00616         }
00617     }
00618 
00619     /**
00620      * Sets the content tree menu timestamp to the current date and time,
00621      * this is used as a GET parameter in the content/treemenu requests and thus
00622      * forces a browser to load the content tree menu from a server rather than
00623      * to use a cached copy.
00624      */
00625     static function clearContentTreeMenu( $cacheItem )
00626     {
00627         eZExpiryHandler::registerShutdownFunction();
00628         $expiryHandler = eZExpiryHandler::instance();
00629         $expiryHandler->setTimestamp( 'content-tree-menu', time() );
00630         $expiryHandler->store();
00631     }
00632 
00633     /**
00634      * Removes all template block cache files and subtree entries.
00635      */
00636     static function clearTemplateBlockCache( $cacheItem )
00637     {
00638         eZExpiryHandler::registerShutdownFunction();
00639         $expiryHandler = eZExpiryHandler::instance();
00640         $expiryHandler->setTimestamp( 'global-template-block-cache', time() );
00641         $expiryHandler->store();
00642     }
00643 
00644     /**
00645      * Removes all template override cache files, subtree entries
00646      * and clears in memory override cache.
00647      *
00648      * @since 4.2
00649     */
00650     static function clearTemplateOverrideCache( $cacheItem )
00651     {
00652         $cachePath = eZSys::cacheDirectory() . '/' . $cacheItem['path'];
00653         eZDir::recursiveDelete( $cachePath );
00654         eZTemplateDesignResource::clearInMemoryOverrideArray();
00655     }
00656 
00657     /**
00658      * Clears all content class identifier cache files from var/cache.
00659      */
00660     static function clearClassID( $cacheItem )
00661     {
00662         $cachePath = eZSys::cacheDirectory();
00663 
00664         $fileHandler = eZClusterFileHandler::instance();
00665         $fileHandler->fileDelete( $cachePath, 'classidentifiers_' );
00666         $fileHandler->fileDelete( $cachePath, 'classattributeidentifiers_' );
00667         eZContentClass::expireCache();
00668     }
00669 
00670     /**
00671      * Clears all datatype sortkey cache files from var/cache.
00672      */
00673     static function clearSortKey( $cacheItem )
00674     {
00675         $cachePath = eZSys::cacheDirectory();
00676 
00677         $fileHandler = eZClusterFileHandler::instance();
00678         $fileHandler->fileDelete( $cachePath, 'sortkey_' );
00679     }
00680 
00681     /**
00682      * Clears all user-info caches by setting a new expiry value for the key *user-info-cache*.
00683      */
00684     static function clearUserInfoCache( $cacheItem )
00685     {
00686         eZExpiryHandler::registerShutdownFunction();
00687         $handler = eZExpiryHandler::instance();
00688         $handler->setTimestamp( 'user-info-cache', time() );
00689         $handler->store();
00690     }
00691 
00692     /**
00693      * Clears all content caches by setting a new expiry value for the key *content-view-cache*.
00694      */
00695     static function clearContentCache( $cacheItem )
00696     {
00697         eZExpiryHandler::registerShutdownFunction();
00698         $handler = eZExpiryHandler::instance();
00699         $handler->setTimestamp( 'content-view-cache', time() );
00700         $handler->store();
00701     }
00702 
00703     /**
00704      * Clear global ini cache
00705      */
00706     static function clearGlobalINICache( $cacheItem )
00707     {
00708         eZDir::recursiveDelete( $cacheItem['path'] );
00709     }
00710 
00711     /**
00712      * Clear texttoimage cache
00713      */
00714     static function clearTextToImageCache( $cacheItem )
00715     {
00716         $fileHandler = eZClusterFileHandler::instance( $cacheItem['path'] );
00717         $fileHandler->delete();
00718     }
00719 
00720     /**
00721      * Purge texttoimage cache
00722      */
00723     static function purgeTextToImageCache( $cacheItem )
00724     {
00725         $fileHandler = eZClusterFileHandler::instance( $cacheItem['path'] );
00726         $fileHandler->purge();
00727     }
00728 
00729     /**
00730      * Clears all state limitation cache files.
00731      */
00732     static function clearStateLimitations( $cacheItem )
00733     {
00734         $cachePath = eZSys::cacheDirectory();
00735 
00736         $fileHandler = eZClusterFileHandler::instance();
00737         $fileHandler->fileDelete( $cachePath, 'statelimitations_' );
00738     }
00739 
00740     /**
00741      * Clears active extensions list cache
00742      */
00743     static function clearActiveExtensions( $cacheItem )
00744     {
00745         eZExpiryHandler::registerShutdownFunction();
00746 
00747         $handler = eZExpiryHandler::instance();
00748         $handler->setTimestamp( $cacheItem['expiry-key'], time() );
00749         $handler->store();
00750 
00751         eZExtension::clearActiveExtensionsMemoryCache();
00752     }
00753 
00754     /**
00755      * Clears the design base cache
00756      *
00757      * @param $cacheItem array the cache item that describes the cache tag/id
00758      */
00759     public static function clearDesignBaseCache( $cacheItem )
00760     {
00761         $cachePath = eZSys::cacheDirectory();
00762 
00763         $fileHandler = eZClusterFileHandler::instance();
00764         if ( !$fileHandler instanceof eZDBFileHandler )
00765         {
00766             // design base cache is disabled with eZDBFileHandler cluster
00767             // handler, see eZTemplateDesignResource::allDesignBases()
00768             $fileHandler->fileDelete(
00769                 $cachePath, eZTemplateDesignResource::DESIGN_BASE_CACHE_NAME
00770             );
00771         }
00772     }
00773 
00774     /**
00775      * Clears the .ts translation cache
00776      * @param array $cacheItem
00777      * @return void
00778      */
00779     public static function clearTSTranslationCache( $cacheItem )
00780     {
00781         eZTSTranslator::expireCache();
00782     }
00783 }
00784 
00785 /**
00786  * Helper function for eZCache::clearImageAlias.
00787  * Static functions in classes cannot be used as callback functions in PHP 4, that is why we need this helper.
00788  *
00789  * @deprecated Callback to static class function is now done directly.
00790  */
00791 function eZCacheClearImageAlias( $cacheItem )
00792 {
00793     eZCache::clearImageAlias( $cacheItem );
00794 }
00795 
00796 /**
00797  * Helper function for eZCache::clearClassID.
00798  * Static functions in classes cannot be used as callback functions in PHP 4, that is why we need this helper.
00799  * @deprecated Callback to static class function is now done directly.
00800  */
00801 function eZCacheClearClassID( $cacheItem )
00802 {
00803     eZCache::clearClassID( $cacheItem );
00804 }
00805 
00806 /**
00807  * Helper function for eZCache::clearGlobalINICache.
00808  * Static functions in classes cannot be used as callback functions in PHP 4, that is why we need this helper.
00809  * @deprecated Callback to static class function is now done directly.
00810  */
00811 function eZCacheClearGlobalINI( $cacheItem )
00812 {
00813     eZCache::clearGlobalINICache( $cacheItem );
00814 }
00815 
00816 /**
00817  *
00818  * Helper function for eZCache::clearSortKey.
00819  * Static functions in classes cannot be used as callback functions in PHP 4, that is why we need this helper.
00820  * @deprecated Callback to static class function is now done directly.
00821  */
00822 function eZCacheClearSortKey( $cacheItem )
00823 {
00824     eZCache::clearSortKey( $cacheItem );
00825 }
00826 
00827 /**
00828  * Helper function for eZCache::clearTemplateBlockCache.
00829  * Static functions in classes cannot be used as callback functions in PHP 4, that is why we need this helper.
00830  * @deprecated Callback to static class function is now done directly.
00831  */
00832 function eZCacheClearTemplateBlockCache( $cacheItem )
00833 {
00834     eZCache::clearTemplateBlockCache( $cacheItem );
00835 }
00836 
00837 /**
00838  *
00839  * Helper function for eZCache::clearContentTreeMenu.
00840  * Static functions in classes cannot be used as callback functions in PHP 4, that is why we need this helper.
00841  * @deprecated Callback to static class function is now done directly.
00842  */
00843 function eZCacheClearContentTreeMenu( $cacheItem )
00844 {
00845     eZCache::clearContentTreeMenu( $cacheItem );
00846 }
00847 
00848 ?>