Starts cache generation for the current file.

This is done by creating a file named by the original file name, prefixed
with '.generating'.

@return bool false if the file is being generated, true if it is not
773795
public function startCacheGeneration()
    {
        eZDebugSetting::writeDebug( 'kernel-clustering', "Starting cache generation", "dfs::startCacheGeneration( '{$this->filePath}' )" );

        $generatingFilePath = $this->filePath . '.generating';
        try {
            $ret = self::$dbbackend->_startCacheGeneration( $this->filePath, $generatingFilePath );
        } catch( RuntimeException $e ) {
            eZDebug::writeError( $e->getMessage() );
            return false;
        }

        // generation granted
        if ( $ret['result'] == 'ok' )
        {
            eZClusterFileHandler::addGeneratingFile( $this );
            $this->realFilePath = $this->filePath;
            $this->filePath = $generatingFilePath;
            $this->generationStartTimestamp = $ret['mtime'];
            return true;
        }
        // failure: the file is being generated
        elseif ( $ret['result'] == 'ko' )
        {
            return $ret['remaining'];
        }
        // unhandled error case, should not happen
        else
        {
            eZLog::write( "An error occured starting cache generation on '$generatingFilePath'", 'cluster.log' );
            return false;
        }
    }
1232096
private function _create_cache_dir()
    {
        if (! file_exists($this->config['cache_dir'])) {
            try {
                mkdir($this->config['cache_dir'], 0755, TRUE);
            } catch (Exception $e) {
                throw $e;
            }
        }
        
        // Set the cache dir
        $this->cache_dir = $this->config['cache_dir'];
    }
19392
public function start()
    {
        if (!$this->isActive()) {
            return true;
        }

        if (!$this->hasCache()) {
            ob_start();
            return true;
        }

        $this->getCache(true);
        return false;
    }
266226
protected function _buildCache()
    {
        $cacheTpl = "<?php\n\$source_version=%s;\n\$cache_version=%s;\n\$properties=%s;\n\$browsers=%s;\n\$userAgents=%s;\n\$patterns=%s;\n";

        $propertiesArray = $this->_array2string($this->_properties);
        $patternsArray = $this->_array2string($this->_patterns);
        $userAgentsArray = $this->_array2string($this->_userAgents);
        $browsersArray = $this->_array2string($this->_browsers);

        return sprintf(
            $cacheTpl,
            "'" . $this->_source_version . "'",
            "'" . self::CACHE_FILE_VERSION . "'",
            $propertiesArray,
            $browsersArray,
            $userAgentsArray,
            $patternsArray
        );
    }
263247
public function generateCachedFile($type, $fileName)
    {
        $isValid = $this->validateCache($fileName);
                
        // If the cache isn't valid, we build the cache
        $result = $isValid;
        if (!$isValid) {
            $result = $this->buildFileCache($type, $fileName);
        }
        
        // If the cache is valid, load the file
        if ($result) {
            $hash = $this->getHash($fileName);
            return $this->cachedFiles[$hash];
        }
        
        return false;
    }
556546
protected function _initCache()
    {
        if (!Cache::getConfig(static::$cacheConfig)) {
            Cache::setConfig(static::$cacheConfig, [
                'className' => $this->_getDefaultCacheConfigClassName(),
                'prefix' => static::$cacheConfig . '_' . $this->_identifier,
                'duration' => $this->getConfig('interval'),
            ]);
        }
    }
261408
protected function loadFromCache()
    {
        $this->log->debug("Load from cache file {$this->filePath}");
        $data = $this->getDataFromFile();
        if ($data === false) {
            $data = '';
        }

        // validate data through parser
        if (!$this->isDataValid($data)) {
            $this->addError($this->filePath, 'Data not valid according to parser');

            return false;
        }

        // verify if local cache is expired
        if ($this->isCacheExpired()) {
            $this->addError($this->filePath, 'Local cache is expired');

            return false;
        }

        return true;
    }
557393
protected function createCacheFile()
    {
        $this->createCacheDir();

        $cacheFilePath = $this->getCacheFile();

        if ( ! file_exists($cacheFilePath)) {
            touch($cacheFilePath);
        }
    }
1281383
protected function loadCache()
    {
        if (file_exists($this->cacheFile)) {
            $this->routes = require $this->cacheFile;
            $this->cacheLoaded = true;
            return true;
        }

        return false;
    }
186906
public function createCache()
    {
        // Check if there are files in the cache.
        // If not we will fill the cache, if there are we will check if there have been any changes to the enforced dirs
        $fileIterator = new \FilesystemIterator($this->getConfig()->getValue('cache/dir'), \FilesystemIterator::SKIP_DOTS);
        if (iterator_count($fileIterator) <= 1 || $this->getConfig()->getValue('environment') === 'development') {
            // Fill the cache
            $this->fillCache();

        } else {
            if (!$this->structureMap->isRecent()) {
                $this->refillCache();
            }
        }
    }
319052
public function useCache()
    {
        if (is_callable($this->get_cache_callback)
            && is_callable($this->set_cache_callback)
            && is_callable($this->delete_cache_callback)) {
            return true;
        }

        return false;
    }
103173
protected function cachedFile()
    {
        if (null === $this->cachedFile) {
            $this->cachedFile = rtrim($this->dir, '/') . '/' . ltrim($this->filename, '/');
        }

        return $this->cachedFile;
    }
1014890
public function createCacheFile(string $hash, string $fileName, ?string $context = null): bool
    {
        foreach ($this->cacheAdapters as $cacheAdapter) {
            if ($cacheAdapter->create($hash, $fileName, $context)) {
                return true;
            }
        }

        return false;
    }
1232654
public function isCacheValid() : bool
    {
        if ($this->fileName === null) {
            return true;
        }

        return $this->fileModificationTime === filemtime($this->fileName);
    }
845815
protected static function initCache()
    {
        // Build namespace for cache
        $namespace = self::$registry->getParameter('doozr.namespace.flat').'.cache';
        $container = self::$registry->getParameter('doozr.kernel.caching.container');
        $unix      = self::$registry->getParameter('doozr.unix');
        $caching   = self::$registry->getParameter('doozr.kernel.caching');

        // Store cache ...
        self::$registry->setCache(
            Doozr_Loader_Serviceloader::load(
                'cache',
                $container,
                $namespace,
                [],
                $unix,
                $caching
            )
        );

        // Important for bootstrap result
        return true;
    }
104754
protected function loadFromCacheCache(): bool
    {
        if (file_exists($this->cacheFileName())) {
            $content = @file_get_contents($this->cacheFileName());
            if ($content) {
                TypeRegistry::setTypeMapping(unserialize($content));

                return true;
            }
        }

        return false;
    }
344783
private function getCache()
    {
        $cachePath = $this->getCachePath();

        if (!$this->files->exists($cachePath)) {
            $this->createCache();

            $this->optimize();
        }

        return collect(json_decode($this->files->get($cachePath), true));
    }