Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezsubtreecache.php
Go to the documentation of this file.
1 <?php
17 class eZSubtreeCache
18 {
25 static function cleanupByNodeIDs( &$nodeIDList )
26 {
27 if ( !is_array( $nodeIDList ) || count( $nodeIDList ) === 0 )
28 {
29 eZSubtreeCache::cleanupAll();
30 }
31 else
32 {
33 $nodeList = eZContentObjectTreeNode::fetch( $nodeIDList );
34 if ( $nodeList )
35 {
36 if ( !is_array( $nodeList ) )
37 $nodeList = array( $nodeList );
38
39 eZSubtreeCache::cleanup( $nodeList );
40 }
41 }
42 }
43
50 static function cleanup( &$nodeList )
51 {
52 if ( !is_array( $nodeList ) )
53 return;
54
55 $cacheDir = eZTemplateCacheBlock::templateBlockCacheDir();
56
57 foreach ( $nodeList as $node )
58 {
59 $pathString = $node->attribute( 'path_string' );
60 $pathString = trim( $pathString, '/' );
61 $nodeListID = explode( '/', $pathString );
62
63 foreach( $nodeListID as $nodeID )
64 {
65 $cachePath = $cacheDir . eZTemplateCacheBlock::subtreeCacheSubDirForNode( $nodeID );
66 eZSubtreeCache::cleanupCacheDir( $cachePath );
67 }
68 }
69 }
70
75 static function cleanupAll()
76 {
77 $subtreeCacheDir = eZTemplateCacheBlock::templateBlockCacheDir() . eZTemplateCacheBlock::subtreeCacheBaseSubDir();
78 eZSubtreeCache::cleanupCacheDir( $subtreeCacheDir );
79 }
80
85 static function cleanupCacheDir( $cacheDir )
86 {
87 $ini = eZINI::instance();
88 if ( $ini->variable( 'TemplateSettings', 'DelayedCacheBlockCleanup' ) === 'enabled' )
89 {
90 eZSubtreeCache::renameDir( $cacheDir );
91 }
92 else
93 {
94 eZSubtreeCache::removeExpiryCacheFromDisk( $cacheDir );
95 }
96 }
97
103 static function renameDir( $dir )
104 {
105 // just rename. Actual removing will be performed by cronjob.
106
107 // This directory renaming is only performed on the local filesystem
108 // to ensure purging of really old data. If the DB file handler is in
109 // use it will check the modified_subnode field of the tree structure
110 // to determin expiry when the cache-block entry is accessed.
111 if ( file_exists( $dir ) )
112 {
113 if ( is_dir( $dir ) )
114 {
115 $uniqid = md5( uniqid( 'ezpsubtreecache'. getmypid(), true ) );
116 $expiryCacheDir = eZSys::cacheDirectory() . '/template-block-expiry/' . $uniqid[0] . '/' . $uniqid[1] . '/' . $uniqid[2] . '/' . $uniqid;
117
118 if ( !file_exists( $expiryCacheDir ) )
119 {
120 eZDir::mkdir( $expiryCacheDir, false, true );
121 }
122 eZFile::rename( $dir, $expiryCacheDir, false, eZFile::APPEND_DEBUG_ON_FAILURE );
123 }
124 else
125 {
126 eZDebug::writeWarning( "$dir should be a directory. Template-block caches for 'subtree_expiry' are not removed.", __METHOD__ );
127 }
128 }
129 }
130
134 static function removeAllExpiryCacheFromDisk()
135 {
136 eZSubtreeCache::removeExpiryCacheFromDisk( eZSys::cacheDirectory() . '/template-block-expiry' );
137 }
138
143 static function removeExpiryCacheFromDisk( $expiryCachePath )
144 {
145 $fileHandler = eZClusterFileHandler::instance();
146 if ( $fileHandler instanceof eZFSFileHandler )
147 {
148 // We will only delete files if the FS file handler is used,
149 // if the DB file handler is in use the system will
150 // instead use the modified_subnode field from the tree structure
151 // in the database to determine if the cache is expired.
152 // This reduces the need to perform expensive modifications to the
153 // database entries for the cluster storage.
154 $fileHandler->fileDelete( $expiryCachePath );
155 }
156 }
157 }
158
159 ?>
eZClusterFileHandler\instance
static instance( $filename=false)
Definition: ezclusterfilehandler.php:21
eZContentObjectTreeNode\fetch
static fetch( $nodeID=false, $lang=false, $asObject=true, $conditions=false)
Definition: ezcontentobjecttreenode.php:3058
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:502
eZDir\mkdir
static mkdir( $dir, $perm=false, $recursive=false)
Definition: ezdir.php:73
eZFSFileHandler
Definition: ezfsfilehandler.php:12
eZFile\rename
static rename( $srcFile, $destFile, $mkdir=false, $flags=0)
Definition: ezfile.php:152
eZFile\APPEND_DEBUG_ON_FAILURE
const APPEND_DEBUG_ON_FAILURE
Definition: ezfile.php:32
eZSubtreeCache
The class eZSubtreeCache does.
Definition: ezsubtreecache.php:18
eZSubtreeCache\cleanupByNodeIDs
static cleanupByNodeIDs(&$nodeIDList)
Definition: ezsubtreecache.php:25
eZSubtreeCache\cleanupAll
static cleanupAll()
Definition: ezsubtreecache.php:75
eZSubtreeCache\removeExpiryCacheFromDisk
static removeExpiryCacheFromDisk( $expiryCachePath)
Definition: ezsubtreecache.php:143
eZSubtreeCache\cleanup
static cleanup(&$nodeList)
Definition: ezsubtreecache.php:50
eZSubtreeCache\removeAllExpiryCacheFromDisk
static removeAllExpiryCacheFromDisk()
Definition: ezsubtreecache.php:134
eZSubtreeCache\renameDir
static renameDir( $dir)
Definition: ezsubtreecache.php:103
eZSubtreeCache\cleanupCacheDir
static cleanupCacheDir( $cacheDir)
Definition: ezsubtreecache.php:85
eZSys\cacheDirectory
static cacheDirectory()
Definition: ezsys.php:527
eZTemplateCacheBlock\templateBlockCacheDir
static templateBlockCacheDir()
Definition: eztemplatecacheblock.php:190
eZTemplateCacheBlock\subtreeCacheSubDirForNode
static subtreeCacheSubDirForNode( $nodeID)
Definition: eztemplatecacheblock.php:286
eZTemplateCacheBlock\subtreeCacheBaseSubDir
static subtreeCacheBaseSubDir()
Definition: eztemplatecacheblock.php:314
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.