public function __construct( $location = null, array $options = array() ) { eZExpiryHandler::registerShutdownFunction(); $this->expiryHandler = eZExpiryHandler::instance(); parent::__construct( $location, $options ); }
static function fetchIDListByUserID($userID) { if ($userID == eZUser::anonymousId()) { $userCache = eZUSer::getUserCacheByAnonymousId(); $ruleArray = $userCache['discount_rules']; } else { $http = eZHTTPTool::instance(); eZExpiryHandler::registerShutdownFunction(); $handler = eZExpiryHandler::instance(); $expiredTimeStamp = 0; if ($handler->hasTimestamp('user-discountrules-cache')) { $expiredTimeStamp = $handler->timestamp('user-discountrules-cache'); } $ruleTimestamp =& $http->sessionVariable('eZUserDiscountRulesTimestamp'); $ruleArray = false; // check for cached version in session if ($ruleTimestamp > $expiredTimeStamp) { if ($http->hasSessionVariable('eZUserDiscountRules' . $userID)) { $ruleArray =& $http->sessionVariable('eZUserDiscountRules' . $userID); } } if (!is_array($ruleArray)) { $ruleArray = self::generateIDListByUserID((int) $userID); $http->setSessionVariable('eZUserDiscountRules' . $userID, $ruleArray); $http->setSessionVariable('eZUserDiscountRulesTimestamp', time()); } } $rules = array(); foreach ($ruleArray as $ruleRow) { $rules[] = $ruleRow['id']; } return $rules; }
static function handle( $cachePath, $nodeID, $ttl, $useGlobalExpiry = true ) { $globalExpiryTime = -1; eZExpiryHandler::registerShutdownFunction(); if ( $useGlobalExpiry ) { $globalExpiryTime = eZExpiryHandler::getTimestamp( 'template-block-cache', -1 ); } $cacheHandler = eZClusterFileHandler::instance( $cachePath ); $subtreeExpiry = -1; // Perform an extra check if the DB handler is in use, // get the modified_subnode value from the specified node ($nodeID) // and use it as an extra expiry value. if ( $cacheHandler instanceof eZDBFileHandler or $cacheHandler instanceof eZDFSFileHandler ) { $subtreeExpiry = eZTemplateCacheBlock::getSubtreeModification( $nodeID ); } $globalExpiryTime = max( eZExpiryHandler::getTimestamp( 'global-template-block-cache', -1 ), // This expiry value is the true global expiry for cache-blocks $globalExpiryTime, $subtreeExpiry ); if ( $ttl == 0 ) $ttl = -1; return array( &$cacheHandler, $cacheHandler->processCache( array( 'eZTemplateCacheBlock', 'retrieveContent' ), null, $ttl, $globalExpiryTime ) ); }
/** * Test scenario for issue #014897: Object/class name pattern and cache issues [patch] * * @result $phpCache->canRestore() returns true * @expected $phpCache->canRestore() should return false * * @link http://issues.ez.no/14897 */ public function testCanRestore() { $db = eZDB::instance(); $dbName = md5($db->DB); $cacheDir = eZSys::cacheDirectory(); $phpCache = new eZPHPCreator($cacheDir, 'classidentifiers_' . $dbName . '.php', '', array('clustering' => 'classidentifiers')); eZExpiryHandler::registerShutdownFunction(); $handler = eZExpiryHandler::instance(); $expiryTime = 0; if ($handler->hasTimestamp('class-identifier-cache')) { $expiryTime = $handler->timestamp('class-identifier-cache'); } $this->assertFalse($phpCache->canRestore($expiryTime)); }
/** * Expire user access / info cache globally */ static function cleanupCache() { eZExpiryHandler::registerShutdownFunction(); $handler = eZExpiryHandler::instance(); $handler->setTimestamp('user-info-cache', time()); $handler->store(); }
/** * Returns the class identifier hash for the current database. * If it is outdated or non-existent, the method updates/generates the file * * @static * @since Version 4.1 * @access protected * @return array Returns hash of classidentifier => classid */ protected static function classIdentifiersHash() { if (self::$identifierHash === null) { $db = eZDB::instance(); $dbName = md5($db->DB); $cacheDir = eZSys::cacheDirectory(); $phpCache = new eZPHPCreator($cacheDir, 'classidentifiers_' . $dbName . '.php', '', array('clustering' => 'classidentifiers')); eZExpiryHandler::registerShutdownFunction(); $handler = eZExpiryHandler::instance(); $expiryTime = 0; if ($handler->hasTimestamp('class-identifier-cache')) { $expiryTime = $handler->timestamp('class-identifier-cache'); } if ($phpCache->canRestore($expiryTime)) { $var = $phpCache->restore(array('identifierHash' => 'identifier_hash')); self::$identifierHash = $var['identifierHash']; } else { // Fetch identifier/id pair from db $query = "SELECT id, identifier FROM ezcontentclass where version=0"; $identifierArray = $db->arrayQuery($query); self::$identifierHash = array(); foreach ($identifierArray as $identifierRow) { self::$identifierHash[$identifierRow['identifier']] = $identifierRow['id']; } // Store identifier list to cache file $phpCache->addVariable('identifier_hash', self::$identifierHash); $phpCache->store(); } } return self::$identifierHash; }
static public function fetchContentTreeMenuExpiry() { eZExpiryHandler::registerShutdownFunction(); $expiryHandler = eZExpiryHandler::instance(); if ( !$expiryHandler->hasTimestamp( 'content-tree-menu' ) ) { $expiryHandler->setTimestamp( 'content-tree-menu', time() ); $expiryHandler->store(); } return array( 'result' => $expiryHandler->timestamp( 'content-tree-menu' ) ); }
/** * Clears active extensions list cache */ static function clearActiveExtensions($cacheItem) { eZExpiryHandler::registerShutdownFunction(); $handler = eZExpiryHandler::instance(); $handler->setTimestamp($cacheItem['expiry-key'], time()); $handler->store(); eZExtension::clearActiveExtensionsMemoryCache(); }
static function isComplexViewModeCacheExpired( $viewMode, $timestamp ) { if ( !eZContentObject::isComplexViewMode( $viewMode ) ) return false; eZExpiryHandler::registerShutdownFunction(); $handler = eZExpiryHandler::instance(); if ( !$handler->hasTimestamp( 'content-complex-viewmode-cache' ) ) return false; $expiryTime = $handler->timestamp( 'content-complex-viewmode-cache' ); if ( $expiryTime > $timestamp ) return true; return false; }
/** * Expires the translation cache * * @param int $timestamp An optional timestamp cache should be exired from. Current timestamp used by default * * @return void */ public static function expireCache($timestamp = false) { eZExpiryHandler::registerShutdownFunction(); if ($timestamp === false) { $timestamp = time(); } $handler = eZExpiryHandler::instance(); $handler->setTimestamp(self::EXPIRY_KEY, $timestamp); $handler->store(); self::$expiryTimestamp = $timestamp; }
function processCached( $tpl, $functionChildren, $rootNamespace, $currentNamespace, $placementString, $keys, $subtreeExpiry, $expiry, $ignoreContentExpiry ) { // Fetch the current siteaccess $accessName = false; if ( isset( $GLOBALS['eZCurrentAccess']['name'] ) ) $accessName = $GLOBALS['eZCurrentAccess']['name']; if ( $keys === null ) { $keyArray = array( $placementString, $accessName ); } else { $keyArray = array( $keys, $placementString, $accessName ); } $nodeID = $subtreeExpiry ? eZTemplateCacheBlock::decodeNodeID( $subtreeExpiry ) : false; $phpPath = eZTemplateCacheBlock::cachePath( eZTemplateCacheBlock::keyString( $keyArray ), $nodeID ); $ttl = $expiry > 0 ? $expiry : null; if ( $subtreeExpiry !== null ) { $ignoreContentExpiry = true; } else if ( $ignoreContentExpiry === null ) { $ignoreContentExpiry = false; } $globalExpiryTime = -1; eZExpiryHandler::registerShutdownFunction(); if ( $ignoreContentExpiry == false ) { $globalExpiryTime = eZExpiryHandler::getTimestamp( 'template-block-cache', -1 ); } $globalExpiryTime = max( eZExpiryHandler::getTimestamp( 'global-template-block-cache', -1 ), // This expiry value is the true global expiry for cache-blocks $globalExpiryTime ); // Check if we can restore $cacheFile = eZClusterFileHandler::instance( $phpPath ); $args = array( "tpl" => $tpl, "functionChildren" => $functionChildren, "rootNamespace" => $rootNamespace, "currentNamespace" => $currentNamespace ); return $cacheFile->processCache( array( 'eZTemplateCacheBlock', 'retrieveContent' ), array( $this, 'generateProcessedContent' ), $ttl, $globalExpiryTime, $args ); }
function revertFromTemporaryVersion() { $temporaryVersion = eZRole::fetch(0, $this->attribute('id')); if ($temporaryVersion === null) { return 0; } $this->removePolicies(); $this->setAttribute('name', $temporaryVersion->attribute('name')); $this->setAttribute('is_new', 0); $db = eZDB::instance(); $db->begin(); $this->store(); $query = "UPDATE ezpolicy\n SET role_id = " . $this->attribute('id') . "\n WHERE role_id = " . $temporaryVersion->attribute('id'); $db->query($query); $temporaryVersion->removePolicies(false); $temporaryVersion->remove(); $db->commit(); // Expire role cache eZExpiryHandler::registerShutdownFunction(); $handler = eZExpiryHandler::instance(); $handler->setTimestamp('user-info-cache', time()); $handler->setTimestamp('user-class-cache', time()); $handler->store(); }
/** * Returns an array of limitations useable by the policy system * * @return array */ public static function limitations() { static $limitations; if ( $limitations === null ) { $db = eZDB::instance(); $dbName = md5( $db->DB ); $cacheDir = eZSys::cacheDirectory(); $phpCache = new eZPHPCreator( $cacheDir, 'statelimitations_' . $dbName . '.php', '', array( 'clustering' => 'statelimitations' ) ); $handler = eZExpiryHandler::instance(); $storedTimeStamp = $handler->hasTimestamp( 'state-limitations' ) ? $handler->timestamp( 'state-limitations' ) : false; $expiryTime = $storedTimeStamp !== false ? $storedTimeStamp : 0; if ( $phpCache->canRestore( $expiryTime ) ) { $var = $phpCache->restore( array( 'state_limitations' => 'state_limitations' ) ); $limitations = $var['state_limitations']; } else { $limitations = array(); $groups = self::fetchByConditions( array( "identifier NOT LIKE 'ez%'" ), false, false ); foreach ( $groups as $group ) { $name = 'StateGroup_' . $group->attribute( 'identifier' ); $limitations[$name] = array( 'name' => $name, 'values' => array(), 'class' => __CLASS__, 'function' => 'limitationValues', 'parameter' => array( $group->attribute( 'id' ) ) ); } $phpCache->addVariable( 'state_limitations', $limitations ); $phpCache->store(); } if ( $storedTimeStamp === false ) { eZExpiryHandler::registerShutdownFunction(); $handler->setTimestamp( 'state-limitations', time() ); } } return $limitations; }
/** * Returns the class attribute identifier hash for the current database. * If it is outdated or non-existent, the method updates/generates the file * * @static * @since Version 4.1 * @access protected * @return array Returns hash of classattributeidentifier => classattributeid */ protected static function classAttributeIdentifiersHash() { if (self::$identifierHash === null) { $db = eZDB::instance(); $dbName = md5($db->DB); $cacheDir = eZSys::cacheDirectory(); $phpCache = new eZPHPCreator($cacheDir, 'classattributeidentifiers_' . $dbName . '.php', '', array('clustering' => 'classattridentifiers')); eZExpiryHandler::registerShutdownFunction(); $handler = eZExpiryHandler::instance(); $expiryTime = 0; if ($handler->hasTimestamp('class-identifier-cache')) { $expiryTime = $handler->timestamp('class-identifier-cache'); } if ($phpCache->canRestore($expiryTime)) { $var = $phpCache->restore(array('identifierHash' => 'identifier_hash')); self::$identifierHash = $var['identifierHash']; } else { // Fetch identifier/id pair from db $query = "SELECT ezcontentclass_attribute.id as attribute_id, ezcontentclass_attribute.identifier as attribute_identifier, ezcontentclass.identifier as class_identifier\n FROM ezcontentclass_attribute, ezcontentclass\n WHERE ezcontentclass.id=ezcontentclass_attribute.contentclass_id"; $identifierArray = $db->arrayQuery($query); self::$identifierHash = array(); foreach ($identifierArray as $identifierRow) { $combinedIdentifier = $identifierRow['class_identifier'] . '/' . $identifierRow['attribute_identifier']; self::$identifierHash[$combinedIdentifier] = (int) $identifierRow['attribute_id']; } // Store identifier list to cache file $phpCache->addVariable('identifier_hash', self::$identifierHash); $phpCache->store(); } } return self::$identifierHash; }
// This program is free software; you can redistribute it and/or // modify it under the terms of version 2.0 of the GNU General // Public License as published by the Free Software Foundation. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of version 2.0 of the GNU General // Public License along with this program; if not, write to the Free // Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, // MA 02110-1301, USA. // ## END COPYRIGHT, LICENSE AND WARRANTY NOTICE ## // eZExpiryHandler::registerShutdownFunction(); if (!defined('MAX_AGE')) { define('MAX_AGE', 86400); } function washJS($string) { return str_replace(array("\\", "/", "\n", "\t", "\r", "\\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\\"'), $string); } function arrayToJSON($array) { if ($array) { $result = array(); $resultDict = array(); $isDict = false; $index = 0; foreach ($array as $key => $value) {
function isImageTimestampValid( $timestamp ) { eZExpiryHandler::registerShutdownFunction(); $expiryHandler = eZExpiryHandler::instance(); if ( $expiryHandler->hasTimestamp( 'image-manager-alias' ) ) { $aliasTimestamp = $expiryHandler->timestamp( 'image-manager-alias' ); return ( $timestamp > $aliasTimestamp ); } return true; }
/** * Expires the translation cache * * @param int $timestamp An optional timestamp cache should be exired from. Current timestamp used by default * @param string $locale Optional translation's locale to expire specifically. Expires global ts cache by default. * * @return void */ public static function expireCache($timestamp = false, $locale = null) { eZExpiryHandler::registerShutdownFunction(); if ($timestamp === false) { $timestamp = time(); } $handler = eZExpiryHandler::instance(); if ($locale) { $handler->setTimestamp(self::EXPIRY_KEY . '-' . $locale, $timestamp); } else { $handler->setTimestamp(self::EXPIRY_KEY, $timestamp); } $handler->store(); self::resetGlobals(); }