예제 #1
0
    /**
     * @param string $name
     * @param mixed $value
     * @param string $cacheFileName
     * @return mixed|null
     */
    public static function dailyValue( $name, $value = null, $cacheFileName = null )
    {
        if ( $value === null && isset($memoryCache[$name]) && $cacheFileName === null )
        {
            return self::$memoryCache[$name];
        }
        else
        {
            if (is_null($cacheFileName))
            {
                $cacheFileName = self::DAILY_CACHE_FILE . '_' . ClusterTool::clusterIdentifier();
            }

            $cache = new eZPHPCreator(
                eZSys::cacheDirectory(),
                $cacheFileName . '.php',
                '',
                array()
            );

            $expiryTime = time() - 24 * 3600;

            // reading
            if ($cache->canRestore($expiryTime))
            {
                $values = $cache->restore(array('cacheTable' => 'cacheTable'));

                if (is_null($value))
                {
                    if (isset($values['cacheTable'][$name]))
                    {
                        return $values['cacheTable'][$name];
                    }
                    else
                    {
                        return null;
                    }
                }
            }
            else
            {
                $values = array('cacheTable' => array());
            }

            $values['cacheTable'][$name] = $value;
            if ( $cacheFileName == self::DAILY_CACHE_FILE . '_' . ClusterTool::clusterIdentifier() )
                self::$memoryCache = $values['cacheTable'];

            // writing
            $cache->addVariable('cacheTable', $values['cacheTable']);
            $cache->store(true);
            $cache->close();
        }

        return null;
    }
 /**
  * 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'));
     $handler = eZExpiryHandler::instance();
     $expiryTime = 0;
     if ($handler->hasTimestamp('class-identifier-cache')) {
         $expiryTime = $handler->timestamp('class-identifier-cache');
     }
     $this->assertFalse($phpCache->canRestore($expiryTime));
 }
    /**
     * @param string $name
     * @param mixed $value
     * @return array
     */
    public static function dailyValue( $name, $value = null)
    {
        if ( $value === null && isset($memoryCache[$name]) )
        {
            return self::$memoryCache[$name];
        }
        else
        {
            $cache = new eZPHPCreator(
                eZSys::cacheDirectory(),
                self::GLOBAL_CACHE_FILE . '.php',
                '',
                array() // removed clustering
            );

            $expiryTime = time() - 24 * 3600;

            // reading
            if ($cache->canRestore($expiryTime))
            {
                $values = $cache->restore(array('cacheTable' => 'cacheTable'));
                self::$memoryCache = $values['cacheTable'];

                if (is_null($value))
                {
                    if (isset($values['cacheTable'][$name]))
                    {
                        return $values['cacheTable'][$name];
                    }
                    else
                    {
                        return null;
                    }
                }
            }
            else
            {
                $values = array('cacheTable' => array());
            }

            if ( !is_null($value) )
            {
                $values['cacheTable'][$name] = $value;
                $cache->addVariable('cacheTable', $values['cacheTable']);
                $cache->store(true);
                $cache->close();
            }
        }

        return null;
    }
예제 #4
0
 static function hasCompiledTemplate($key, $timestamp, &$resourceData)
 {
     if (!eZTemplateCompiler::isCompilationEnabled()) {
         return false;
     }
     if (eZTemplateCompiler::alwaysGenerate()) {
         return false;
     }
     $cacheFileName = eZTemplateCompiler::compilationFilename($key, $resourceData);
     $php = new eZPHPCreator(eZTemplateCompiler::compilationDirectory(), $cacheFileName, eZTemplateCompiler::TemplatePrefix());
     $canRestore = $php->canRestore($timestamp);
     $uri = false;
     if ($canRestore) {
         eZDebugSetting::writeDebug('eztemplate-compile', "Cache hit for uri '{$uri}' with key '{$key}'", 'eZTemplateCompiler::hasCompiledTemplate');
     } else {
         eZDebugSetting::writeDebug('eztemplate-compile', "Cache miss for uri '{$uri}' with key '{$key}'", 'eZTemplateCompiler::hasCompiledTemplate');
     }
     return $canRestore;
 }
예제 #5
0
 /**
  * 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;
 }
예제 #6
0
    /**
     * Return an array with activated extensions.
     *
     * @note Default extensions are those who are loaded before a siteaccess are determined while access extensions
     *       are loaded after siteaccess is set.
     *
     * @param false|string $extensionType Decides which extension to include in the list, the follow values are possible:
     *                                    - false - Means add both default and access extensions
     *                                    - 'default' - Add only default extensions
     *                                    - 'access' - Add only access extensions
     * @param eZINI|null $siteINI Optional parameter to be able to only do change on specific instance of site.ini
     * @return array
     */
    public static function activeExtensions( $extensionType = false, eZINI $siteINI = null )
    {
        if ( $siteINI === null )
        {
            $siteINI = eZINI::instance();
        }

        $activeExtensions = array();
        if ( !$extensionType || $extensionType === 'default' )
        {
            $activeExtensions = $siteINI->variable( 'ExtensionSettings', 'ActiveExtensions' );
        }

        if ( !$extensionType || $extensionType === 'access' )
        {
            $activeExtensions = array_merge( $activeExtensions,
                                             $siteINI->variable( 'ExtensionSettings', 'ActiveAccessExtensions' ) );
        }

        if ( isset( $GLOBALS['eZActiveExtensions'] ) )
        {
            $activeExtensions = array_merge( $activeExtensions,
                                             $GLOBALS['eZActiveExtensions'] );
        }

        // return empty array as is to avoid further unneeded overhead
        if ( !isset( $activeExtensions[0] ) )
        {
            return $activeExtensions;
        }

        // return array as is if ordering is disabled to avoid cache overhead
        $activeExtensions = array_unique( $activeExtensions );
        if ( $siteINI->variable( 'ExtensionSettings', 'ExtensionOrdering' ) !== 'enabled' )
        {
            // @todo Introduce a debug setting or re use existing dev mods to check that all extensions exists
            return $activeExtensions;
        }

        $cacheIdentifier = md5( serialize( $activeExtensions ) );
        if ( isset ( self::$activeExtensionsCache[$cacheIdentifier] ) )
        {
            return self::$activeExtensionsCache[$cacheIdentifier];
        }

        // cache has to be stored by siteaccess + $extensionType
        $extensionDirectory = self::baseDirectory();
        $expiryHandler = eZExpiryHandler::instance();
        $phpCache = new eZPHPCreator( self::CACHE_DIR, "active_extensions_{$cacheIdentifier}.php" );
        $expiryTime = $expiryHandler->hasTimestamp( 'active-extensions-cache' ) ? $expiryHandler->timestamp( 'active-extensions-cache' ) : 0;

        if ( !$phpCache->canRestore( $expiryTime ) )
        {
            self::$activeExtensionsCache[$cacheIdentifier] = self::extensionOrdering( $activeExtensions );

            // Check that all extensions defined actually exists before storing cache
            foreach ( self::$activeExtensionsCache[$cacheIdentifier] as $activeExtension )
            {
                if ( !file_exists( $extensionDirectory . '/' . $activeExtension ) )
                {
                    eZDebug::writeError( "Extension '$activeExtension' does not exist, looked for directory '" . $extensionDirectory . '/' . $activeExtension . "'", __METHOD__ );
                }
            }

            $phpCache->addVariable( 'activeExtensions', self::$activeExtensionsCache[$cacheIdentifier] );
            $phpCache->store();
        }
        else
        {
            $data = $phpCache->restore( array( 'activeExtensions' => 'activeExtensions' ) );
            self::$activeExtensionsCache[$cacheIdentifier] = $data['activeExtensions'];
        }

        return self::$activeExtensionsCache[$cacheIdentifier];
    }
예제 #7
0
 static function canRestoreCache($key, $timestamp, $templateFilepath)
 {
     if (!eZTemplateTreeCache::isCacheEnabled()) {
         return false;
     }
     $templateCache =& eZTemplateTreeCache::cacheTable();
     $key = eZTemplateTreeCache::internalKey($key);
     if (isset($templateCache[$key])) {
         return false;
     }
     $cacheFileName = eZTemplateTreeCache::treeCacheFilename($key, $templateFilepath);
     $php = new eZPHPCreator(eZTemplateTreeCache::cacheDirectory(), $cacheFileName);
     return $php->canRestore($timestamp);
 }
예제 #8
0
 static function canRestoreCache($key, $timestamp)
 {
     $translationCache = eZTranslationCache::cacheTable();
     if (isset($translationCache[$key])) {
         return false;
     }
     //         $internalCharset = eZTextCodec::internalCharset();
     //         $cacheFileKey = "$key-$internalCharset";
     $cacheFileKey = $key;
     $cacheFileName = md5($cacheFileKey) . '.php';
     $php = new eZPHPCreator(eZTranslationCache::cacheDirectory(), $cacheFileName);
     return $php->canRestore($timestamp);
 }
 /**
  * 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) {
             $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'));
         $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;
 }