/** * Stops and saves the cache. * @param array dependencies * @return void */ public function end(array $dp = NULL) { if ($this->cache === NULL) { throw new InvalidStateException('Output cache has already been saved.'); } $this->cache->save($this->key, ob_get_flush(), (array) $dp + (array) $this->dependencies); $this->cache = NULL; }
/** * Filters the given file. * @param string * @return string|NULL */ public function processFile($path) { $data = $this->cache->load($path); if ($data === NULL) { $data = $this->filter->processFile($path); if ($data !== NULL) { $this->cache->save($path, $data, array(Cache::CONSTS => 'FilterStream\\FilterStream::REVISION', Cache::FILES => array($path))); } } return $data; }
/** * Renders template to output. * @return void */ public function render() { $cache = new NCache($storage = $this->getCacheStorage(), 'Nette.Template'); $cached = $compiled = $cache->load($this->source); if ($compiled === NULL) { $compiled = $this->compile(); $cache->save($this->source, $compiled, array(NCache::CONSTS => 'NFramework::REVISION')); $cached = $cache->load($this->source); } if ($cached !== NULL && $storage instanceof NPhpFileStorage) { NLimitedScope::load($cached['file'], $this->getParameters()); } else { NLimitedScope::evaluate($compiled, $this->getParameters()); } }
function render() { if ($this->getFile() == NULL) { throw new InvalidStateException("Template file name was not specified."); } $cache = new NCache($storage = $this->getCacheStorage(), 'wplatte'); if ($storage instanceof NPhpFileStorage) { $storage->hint = str_replace(dirname(dirname($this->getFile())), '', $this->getFile()); } $cached = $compiled = $cache->load($this->getFile()); if ($compiled === NULL) { try { $compiled = "<?php\n\n// source file: {$this->getFile()}\n\n?>" . $this->compile(); } catch (NTemplateException $e) { $e->setSourceFile($this->getFile()); throw $e; } $cache->save($this->getFile(), $compiled, array(NCache::FILES => $this->getFile(), NCache::CONSTS => array('NFramework::REVISION', 'WPLATTE_CACHE_VERSION'))); $cache->release(); $cached = $cache->load($this->getFile()); } if ($cached !== NULL && $storage instanceof NPhpFileStorage) { NLimitedScope::load($cached['file'], $this->getParams()); } else { NLimitedScope::evaluate($compiled, $this->getParams()); } }
function render() { if ($this->file == NULL) { throw new InvalidStateException("Template file name was not specified."); } $this->__set('template', $this); $cache = new NCache($storage = $this->getCacheStorage(), 'Nette.FileTemplate'); if ($storage instanceof NTemplateCacheStorage) { $storage->hint = str_replace(dirname(dirname($this->file)), '', $this->file); } $cached = $content = $cache[$this->file]; if ($content === NULL) { try { $content = $this->compile(file_get_contents($this->file)); $content = "<?php\n\n// source file: {$this->file}\n\n?>{$content}"; } catch (NTemplateException $e) { $e->setSourceFile($this->file); throw $e; } $cache->save($this->file, $content, array(NCache::FILES => $this->file, NCache::EXPIRATION => self::$cacheExpire, NCache::CONSTS => 'NFramework::REVISION')); $cache->release(); $cached = $cache[$this->file]; } if ($cached !== NULL && $storage instanceof NTemplateCacheStorage) { NLimitedScope::load($cached['file'], $this->getParams()); fclose($cached['handle']); } else { NLimitedScope::evaluate($content, $this->getParams()); } }
public function __destruct() { if ($this->cache && $this->structure !== $this->loadedStructure) { $this->cache->save('structure', $this->structure); } }
/** * Returns annotations. * @param ReflectionClass|ReflectionMethod|ReflectionProperty * @return array */ public static function getAll(Reflector $r) { if ($r instanceof ReflectionClass) { $type = $r->getName(); $member = ''; } elseif ($r instanceof ReflectionMethod) { $type = $r->getDeclaringClass()->getName(); $member = $r->getName(); } else { $type = $r->getDeclaringClass()->getName(); $member = '$' . $r->getName(); } if (!self::$useReflection) { // auto-expire cache $file = $r instanceof ReflectionClass ? $r->getFileName() : $r->getDeclaringClass()->getFileName(); // will be used later if ($file && isset(self::$timestamps[$file]) && self::$timestamps[$file] !== filemtime($file)) { unset(self::$cache[$type]); } unset(self::$timestamps[$file]); } if (isset(self::$cache[$type][$member])) { // is value cached? return self::$cache[$type][$member]; } if (self::$useReflection === NULL) { // detects whether is reflection available self::$useReflection = (bool) NClassReflection::from(__CLASS__)->getDocComment(); } if (self::$useReflection) { $annotations = self::parseComment($r->getDocComment()); } else { if (!self::$cacheStorage) { // trigger_error('Set a cache storage for annotations parser via NAnnotationParser::setCacheStorage().', E_USER_WARNING); self::$cacheStorage = new NDevNullStorage; } $outerCache = new NCache(self::$cacheStorage, 'Nette.Reflection.Annotations'); if (self::$cache === NULL) { self::$cache = (array) $outerCache->offsetGet('list'); self::$timestamps = isset(self::$cache['*']) ? self::$cache['*'] : array(); } if (!isset(self::$cache[$type]) && $file) { self::$cache['*'][$file] = filemtime($file); self::parseScript($file); $outerCache->save('list', self::$cache); } if (isset(self::$cache[$type][$member])) { $annotations = self::$cache[$type][$member]; } else { $annotations = array(); } } if ($r instanceof ReflectionMethod && !$r->isPrivate() && (!$r->isConstructor() || !empty($annotations['inheritdoc'][0]))) { try { $inherited = self::getAll(new ReflectionMethod(get_parent_class($type), $member)); } catch (ReflectionException $e) { try { $inherited = self::getAll($r->getPrototype()); } catch (ReflectionException $e) { $inherited = array(); } } $annotations += array_intersect_key($inherited, array_flip(self::$inherited)); } return self::$cache[$type][$member] = $annotations; }
/** * Returns system DI container. * @return SystemContainer */ public function createContainer() { if ($cacheDir = $this->getCacheDirectory()) { $cache = new NCache(new NPhpFileStorage($cacheDir), 'Nette.Configurator'); $cacheKey = array($this->params, $this->files); $cached = $cache->load($cacheKey); if (!$cached) { $code = $this->buildContainer($dependencies); $cache->save($cacheKey, $code, array( NCache::FILES => $this->params['productionMode'] ? NULL : $dependencies, )); $cached = $cache->load($cacheKey); } NLimitedScope::load($cached['file'], TRUE); } elseif ($this->files) { throw new InvalidStateException("Set path to temporary directory using setTempDirectory()."); } else { NLimitedScope::evaluate($this->buildContainer()); // back compatibility with Environment } $container = new $this->params['container']['class']; $container->initialize(); NEnvironment::setContext($container); // back compatibility return $container; }
public function __destruct() { if ($this->cache) { $this->cache->save('structure', $this->structure); } }
protected function saveCacheState() { if ($this->observeCache === $this && $this->cache && !$this->sqlBuilder->getSelect() && $this->accessedColumns != $this->previousAccessedColumns) { $this->cache->save($this->getCacheKey(), $this->accessedColumns); } }
/** * Renders template to output. * @return void */ public function render() { if ($this->file == NULL) { // intentionally == throw new InvalidStateException("Template file name was not specified."); } $cache = new NCache($storage = $this->getCacheStorage(), 'Nette.FileTemplate'); if ($storage instanceof NPhpFileStorage) { $storage->hint = str_replace(dirname(dirname($this->file)), '', $this->file); } $cached = $compiled = $cache->load($this->file); if ($compiled === NULL) { try { $compiled = "<?php\n\n// source file: $this->file\n\n?>" . $this->compile(); } catch (NTemplateException $e) { $e->setSourceFile($this->file); throw $e; } $cache->save($this->file, $compiled, array( NCache::FILES => $this->file, NCache::CONSTS => 'NFramework::REVISION', )); $cached = $cache->load($this->file); } if ($cached !== NULL && $storage instanceof NPhpFileStorage) { NLimitedScope::load($cached['file'], $this->getParameters()); } else { NLimitedScope::evaluate($compiled, $this->getParameters()); } }
function render() { if ($this->file == NULL) { throw new InvalidStateException("Template file name was not specified."); } $this->__set('template', $this); $shortName = str_replace(NEnvironment::getVariable('appDir'), '', $this->file); $cache = new NCache($this->getCacheStorage(), 'Nette.Template'); $key = trim(strtr($shortName, '\\/@', '.._'), '.') . '-' . md5($this->file); $cached = $content = $cache[$key]; if ($content === NULL) { if (!$this->getFilters()) { $this->onPrepareFilters($this); } if (!$this->getFilters()) { NLimitedScope::load($this->file, $this->getParams()); return; } $content = $this->compile(file_get_contents($this->file), "file …{$shortName}"); $cache->save($key, $content, array(NCache::FILES => $this->file, NCache::EXPIRE => self::$cacheExpire)); $cache->release(); $cached = $cache[$key]; } if ($cached !== NULL && self::$cacheStorage instanceof NTemplateCacheStorage) { NLimitedScope::load($cached['file'], $this->getParams()); fclose($cached['handle']); } else { NLimitedScope::evaluate($content, $this->getParams()); } }