Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

eztemplatecacheblock.php
Go to the documentation of this file.
1 <?php
17 class eZTemplateCacheBlock
18 {
50 static function retrieve( $keys, $subtreeExpiry, $ttl, $useGlobalExpiry = true )
51 {
52 $keys = (array)$keys;
53 self::filterKeys( $keys );
54 $nodeID = $subtreeExpiry ? eZTemplateCacheBlock::decodeNodeID( $subtreeExpiry ) : false;
55 $cachePath = eZTemplateCacheBlock::cachePath( eZTemplateCacheBlock::keyString( $keys ), $nodeID );
56 return eZTemplateCacheBlock::handle( $cachePath, $nodeID, $ttl, $useGlobalExpiry );
57 }
58
65 static private function filterKeys( array &$keys )
66 {
67 if ( isset( $GLOBALS['eZRequestError'] ) && $GLOBALS['eZRequestError'] === true )
68 {
69 $requestUri = eZSys::requestURI();
70 foreach ( $keys as $i => &$key )
71 {
72 if ( is_array( $key ) )
73 {
74 self::filterKeys( $key );
75 }
76 else if ( $key === $requestUri )
77 {
78 unset( $keys[$i] );
79 }
80 }
81 }
82 }
83
88 static function handle( $cachePath, $nodeID, $ttl, $useGlobalExpiry = true )
89 {
90 $globalExpiryTime = -1;
91 if ( $useGlobalExpiry )
92 {
93 $globalExpiryTime = eZExpiryHandler::getTimestamp( 'template-block-cache', -1 );
94 }
95
96 $cacheHandler = eZClusterFileHandler::instance( $cachePath );
97
98 $subtreeExpiry = -1;
99 // Perform an extra check if the DB handler is in use,
100 // get the modified_subnode value from the specified node ($nodeID)
101 // and use it as an extra expiry value.
102 if ( $cacheHandler instanceof eZDFSFileHandler )
103 {
104 $subtreeExpiry = eZTemplateCacheBlock::getSubtreeModification( $nodeID );
105 }
106 $globalExpiryTime = max( eZExpiryHandler::getTimestamp( 'global-template-block-cache', -1 ), // This expiry value is the true global expiry for cache-blocks
107 $globalExpiryTime,
108 $subtreeExpiry );
109
110 if ( $ttl == 0 )
111 $ttl = -1;
112 return array( &$cacheHandler,
113 $cacheHandler->processCache( array( 'eZTemplateCacheBlock', 'retrieveContent' ), null,
114 $ttl, $globalExpiryTime ) );
115 }
116
121 static function getSubtreeModification( $nodeID )
122 {
123 if ( $nodeID === false )
124 return -1;
125 $nodeID = (int)$nodeID;
126 $sql = "SELECT modified_subnode FROM ezcontentobject_tree WHERE node_id=$nodeID";
127 $db = eZDB::instance();
128 $rows = $db->arrayQuery( $sql );
129 if ( count( $rows ) > 0 )
130 return $rows[0]['modified_subnode'];
131 return -1;
132 }
133
141 static function placementString( $functionPlacement )
142 {
143 $placementString = $functionPlacement[0][0] . "_";
144 $placementString .= $functionPlacement[0][1] . "_";
145 $placementString .= $functionPlacement[1][0] . "_";
146 $placementString .= $functionPlacement[1][1] . "_";
147 $placementString .= $functionPlacement[2];
148 return $placementString;
149 }
150
157 static function keyString( $keys )
158 {
159 return serialize( $keys );
160 }
161
168 static function cachePath( $keyString, $nodeID = false )
169 {
170 $filename = md5( $keyString ) . ".cache";
171
172 $phpDir = eZTemplateCacheBlock::templateBlockCacheDir();
173 if ( is_numeric( $nodeID ) )
174 {
175 $phpDir .= eZTemplateCacheBlock::calculateSubtreeCacheDir( $nodeID, $filename );
176 }
177 else
178 {
179 $phpDir .= $filename[0] . '/' . $filename[1] . '/' . $filename[2];
180 }
181
182 $phpPath = $phpDir . '/' . $filename;
183 return $phpPath;
184 }
185
190 static function templateBlockCacheDir()
191 {
192 $cacheDir = eZSys::cacheDirectory() . '/template-block/' ;
193 return $cacheDir;
194 }
195
205 static function decodeNodeID( $subtreeExpiryParameter )
206 {
207 $nodeID = false;
208 if ( !is_numeric( $subtreeExpiryParameter ) )
209 {
210 $nodePathString = '';
211
212 // clean up $subtreeExpiryParameter
213 $subtreeExpiryParameter = trim( $subtreeExpiryParameter, '/' );
214
215 $nodeID = false;
216 $subtree = $subtreeExpiryParameter;
217
218 if ( $subtree == '' )
219 {
220 // 'subtree_expiry' is empty => use root node.
221 $nodeID = 2;
222 }
223 else
224 {
225 $nonAliasPath = 'content/view/full/';
226
227 if ( strpos( $subtree, $nonAliasPath ) === 0 )
228 {
229 // 'subtree_expiry' is like 'content/view/full/2'
230 $nodeID = (int)substr( $subtree, strlen( $nonAliasPath ) );
231 }
232 else
233 {
234 // 'subtree_expiry' is url_alias
235 $nodeID = eZURLAliasML::fetchNodeIDByPath( $subtree );
236 if ( !$nodeID )
237 {
238 eZDebug::writeError( "Could not find path_string '$subtree' for 'subtree_expiry' node.", __METHOD__ );
239 }
240 else
241 {
242 $nodeID = (int)$nodeID;
243 }
244 }
245 }
246 }
247 else
248 {
249 $nodeID = (int)$subtreeExpiryParameter;
250 }
251 return $nodeID;
252 }
253
260 static function calculateSubtreeCacheDir( $nodeID, $cacheFilename )
261 {
262 $cacheDir = eZTemplateCacheBlock::subtreeCacheSubDirForNode( $nodeID );
263 $cacheDir .= '/' . $cacheFilename[0] . '/' . $cacheFilename[1] . '/' . $cacheFilename[2];
264
265 return $cacheDir;
266 }
267
276 static function subtreeCacheSubDir( $subtreeExpiryParameter, $cacheFilename )
277 {
278 $nodeID = eZTemplateCacheBlock::decodeNodeID( $subtreeExpiryParameter );
279 return eZTemplateCacheBlock::calculateSubtreeCacheDir( $nodeID, $cacheFilename );
280 }
281
286 static function subtreeCacheSubDirForNode( $nodeID )
287 {
288 $cacheDir = eZTemplateCacheBlock::subtreeCacheBaseSubDir();
289
290 if ( is_numeric( $nodeID ) )
291 {
292 $nodeID = (string)$nodeID;
293 $length = strlen( $nodeID );
294 $pos = 0;
295 while ( $pos < $length )
296 {
297 $cacheDir .= '/' . $nodeID[$pos];
298 ++$pos;
299 }
300 }
301 else
302 {
303 eZDebug::writeWarning( "Unable to determine cacheDir for nodeID = $nodeID", __METHOD__ );
304 }
305
306 $cacheDir .= '/cache';
307 return $cacheDir;
308 }
309
314 static function subtreeCacheBaseSubDir()
315 {
316 return 'subtree';
317 }
318
326 static function retrieveContent( $fname, $mtime )
327 {
328 return file_get_contents( $fname );
329 }
330 }
331
332 ?>
eZClusterFileHandler\instance
static instance( $filename=false)
Definition: ezclusterfilehandler.php:21
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\writeWarning
static writeWarning( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:502
eZSys\requestURI
static requestURI()
Definition: ezsys.php:1262
eZSys\cacheDirectory
static cacheDirectory()
Definition: ezsys.php:527
eZTemplateCacheBlock
Cache block.
Definition: eztemplatecacheblock.php:18
eZTemplateCacheBlock\filterKeys
static filterKeys(array &$keys)
Definition: eztemplatecacheblock.php:65
eZTemplateCacheBlock\calculateSubtreeCacheDir
static calculateSubtreeCacheDir( $nodeID, $cacheFilename)
Definition: eztemplatecacheblock.php:260
eZTemplateCacheBlock\keyString
static keyString( $keys)
Definition: eztemplatecacheblock.php:157
eZTemplateCacheBlock\retrieveContent
static retrieveContent( $fname, $mtime)
Definition: eztemplatecacheblock.php:326
eZTemplateCacheBlock\subtreeCacheSubDir
static subtreeCacheSubDir( $subtreeExpiryParameter, $cacheFilename)
Definition: eztemplatecacheblock.php:276
eZTemplateCacheBlock\templateBlockCacheDir
static templateBlockCacheDir()
Definition: eztemplatecacheblock.php:190
eZTemplateCacheBlock\subtreeCacheSubDirForNode
static subtreeCacheSubDirForNode( $nodeID)
Definition: eztemplatecacheblock.php:286
eZTemplateCacheBlock\decodeNodeID
static decodeNodeID( $subtreeExpiryParameter)
Definition: eztemplatecacheblock.php:205
eZTemplateCacheBlock\retrieve
static retrieve( $keys, $subtreeExpiry, $ttl, $useGlobalExpiry=true)
Definition: eztemplatecacheblock.php:50
eZTemplateCacheBlock\handle
static handle( $cachePath, $nodeID, $ttl, $useGlobalExpiry=true)
Definition: eztemplatecacheblock.php:88
eZTemplateCacheBlock\subtreeCacheBaseSubDir
static subtreeCacheBaseSubDir()
Definition: eztemplatecacheblock.php:314
eZTemplateCacheBlock\placementString
static placementString( $functionPlacement)
Definition: eztemplatecacheblock.php:141
eZTemplateCacheBlock\cachePath
static cachePath( $keyString, $nodeID=false)
Definition: eztemplatecacheblock.php:168
eZTemplateCacheBlock\getSubtreeModification
static getSubtreeModification( $nodeID)
Definition: eztemplatecacheblock.php:121
eZURLAliasML\fetchNodeIDByPath
static fetchNodeIDByPath( $uriString, $glob=false)
Definition: ezurlaliasml.php:1396
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.