public static function gmapStaticImageRetrieve($file, $mtime, $args) { if (!eZContentObject::isCacheExpired($mtime)) { return file_get_contents($file); } else { $expiryReason = 'Content cache is expired'; return new eZClusterFileFailure(1, $expiryReason); } }
static function restore($siteDesign, $nodeID, $viewMode, $language, $offset, $roleList, $discountList, $layout, $parameters = array()) { $result = array(); $cachePathInfo = eZContentCache::cachePathInfo($siteDesign, $nodeID, $viewMode, $language, $offset, $roleList, $discountList, $layout, false, $parameters); $cacheDir = $cachePathInfo['dir']; $cacheFile = $cachePathInfo['file']; $cachePath = $cachePathInfo['path']; $timestamp = false; $cacheFile = eZClusterFileHandler::instance($cachePath); if ($cacheFile->exists()) { $timestamp = $cacheFile->mtime(); if (eZContentObject::isCacheExpired($timestamp)) { eZDebugSetting::writeDebug('kernel-content-view-cache', 'cache expired #2'); return false; } eZDebugSetting::writeDebug('kernel-content-view-cache', "checking viewmode '{$viewMode}' #1"); if (eZContentObject::isComplexViewModeCacheExpired($viewMode, $timestamp)) { eZDebugSetting::writeDebug('kernel-content-view-cache', "viewmode '{$viewMode}' cache expired #2"); return false; } } if ($viewMode == 'pdf') { return $cachePath; } eZDebugSetting::writeDebug('kernel-content-view-cache', 'cache used #2'); $fileName = $cacheDir . "/" . $cacheFile; $cacheFile = eZClusterFileHandler::instance($fileName); $contents = $cacheFile->fetchContents(); $cachedArray = unserialize($contents); $cacheTTL = $cachedArray['cache_ttl']; // Check if cache has expired if ($cacheTTL > 0) { $expiryTime = $timestamp + $cacheTTL; if (time() > $expiryTime) { return false; } } // Check for template language timestamp $cacheCodeDate = $cachedArray['cache_code_date']; if ($cacheCodeDate != self::CODE_DATE) { return false; } $viewMode = $cachedArray['content_info']['viewmode']; $res = eZTemplateDesignResource::instance(); $res->setKeys(array(array('node', $nodeID), array('view_offset', $offset), array('viewmode', $viewMode), array('section', $cachedArray['section_id']))); $result['content_info'] = $cachedArray['content_info']; $result['content'] = $cachedArray['content']; $result['view_parameters'] = $cachedArray['content_info']['view_parameters']; foreach (array('path', 'node_id', 'section_id', 'navigation_part') as $item) { if (isset($cachedArray[$item])) { $result[$item] = $cachedArray[$item]; } } return $result; }
/** * Retrieve content view data * * @see contentViewGenerate() * * @param string $file * @param int $mtime File modification time * @param array $args Hash containing arguments, the used ones are: * - ini * * @return \eZClusterFileFailure */ public static function contentViewRetrieve($file, $mtime, $args) { extract($args); $cacheExpired = false; // Read Cache file if (!eZContentObject::isCacheExpired($mtime)) { // $contents = $cacheFile->fetchContents(); $contents = file_get_contents($file); $Result = unserialize($contents); if (!is_array($Result)) { $expiryReason = 'Unexpected cache file content'; $cacheExpired = true; } // Check if a no_cache key has been set in the viewcache, and // return an eZClusterFileFailure if it has if (isset($Result['no_cache'])) { return new eZClusterFileFailure(3, "Cache has been disabled for this node"); } // Check if cache has expired when cache_ttl is set $cacheTTL = isset($Result['cache_ttl']) ? $Result['cache_ttl'] : -1; if ($cacheTTL > 0) { $expiryTime = $mtime + $cacheTTL; if (time() > $expiryTime) { $cacheExpired = true; $expiryReason = 'Content cache is expired by cache_ttl=' . $cacheTTL; } } // Check if template source files are newer, but only if the cache is not expired if (!$cacheExpired) { $developmentModeEnabled = $ini->variable('TemplateSettings', 'DevelopmentMode') == 'enabled'; // Only do filemtime checking when development mode is enabled. if ($developmentModeEnabled && isset($Result['template_list'])) { foreach ($Result['template_list'] as $templateFile) { if (!file_exists($templateFile)) { $cacheExpired = true; $expiryReason = "Content cache is expired by template file '" . $templateFile . "', it does not exist anymore"; break; } else { if (filemtime($templateFile) > $mtime) { $cacheExpired = true; $expiryReason = "Content cache is expired by template file '" . $templateFile . "'"; break; } } } } } if (!$cacheExpired) { if (!isset($Result['content_info'])) { // set error type & number for kernel errors (see https://jira.ez.no/browse/EZP-23046) if (isset($Result['errorType']) && isset($Result['errorNumber'])) { $res = eZTemplateDesignResource::instance(); $res->setKeys(array(array('error_type', $Result['errorType']), array('error_number', $Result['errorNumber']))); } return $Result; } $keyArray = array(array('object', $Result['content_info']['object_id']), array('node', $Result['content_info']['node_id']), array('parent_node', $Result['content_info']['parent_node_id']), array('parent_node_remote_id', $Result['content_info']['parent_node_remote_id']), array('parent_object_remote_id', $Result['content_info']['parent_object_remote_id']), array('class', $Result['content_info']['class_id']), array('view_offset', $Result['content_info']['offset']), array('navigation_part_identifier', $Result['content_info']['navigation_part_identifier']), array('viewmode', $Result['content_info']['viewmode']), array('depth', $Result['content_info']['node_depth']), array('remote_id', $Result['content_info']['remote_id']), array('node_remote_id', $Result['content_info']['node_remote_id']), array('url_alias', $Result['content_info']['url_alias']), array('persistent_variable', $Result['content_info']['persistent_variable']), array('class_group', $Result['content_info']['class_group']), array('parent_class_id', $Result['content_info']['parent_class_id']), array('parent_class_identifier', $Result['content_info']['parent_class_identifier']), array('state', $Result['content_info']['state']), array('state_identifier', $Result['content_info']['state_identifier']), array('section', $Result['section_id'])); if (isset($Result['content_info']['class_identifier'])) { $keyArray[] = array('class_identifier', $Result['content_info']['class_identifier']); } $res = eZTemplateDesignResource::instance(); $res->setKeys($keyArray); return $Result; } } else { $expiryReason = 'Content cache is expired by eZContentObject::isCacheExpired(' . $mtime . ")"; } // Cache is expired so return specialized cluster object if (!isset($expiryReason)) { $expiryReason = 'Content cache is expired'; } return new eZClusterFileFailure(1, $expiryReason); }