当前位置: 首页>>代码示例>>PHP>>正文


PHP Caching\Cache类代码示例

本文整理汇总了PHP中Nette\Caching\Cache的典型用法代码示例。如果您正苦于以下问题:PHP Cache类的具体用法?PHP Cache怎么用?PHP Cache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Cache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createCache

 /**
  * Starts the output cache. Returns Nette\Caching\OutputHelper object if buffering was started.
  * @param  Nette\Caching\IStorage
  * @param  string
  * @param  Nette\Caching\OutputHelper[]
  * @param  array
  * @return Nette\Caching\OutputHelper
  */
 public static function createCache(Nette\Caching\IStorage $cacheStorage, $key, &$parents, array $args = NULL)
 {
     if ($args) {
         if (array_key_exists('if', $args) && !$args['if']) {
             return $parents[] = new \stdClass();
         }
         $key = array_merge([$key], array_intersect_key($args, range(0, count($args))));
     }
     if ($parents) {
         end($parents)->dependencies[Nette\Caching\Cache::ITEMS][] = $key;
     }
     $cache = new Nette\Caching\Cache($cacheStorage, 'Nette.Templating.Cache');
     if ($helper = $cache->start($key)) {
         if (isset($args['dependencies'])) {
             $args += call_user_func($args['dependencies']);
         }
         if (isset($args['expire'])) {
             $args['expiration'] = $args['expire'];
             // back compatibility
         }
         $helper->dependencies = [Nette\Caching\Cache::TAGS => isset($args['tags']) ? $args['tags'] : NULL, Nette\Caching\Cache::EXPIRATION => isset($args['expiration']) ? $args['expiration'] : '+ 7 days'];
         $parents[] = $helper;
     }
     return $helper;
 }
开发者ID:JanTvrdik,项目名称:nette-caching,代码行数:33,代码来源:CacheMacro.php

示例2: loadNavigationFromCache

 private function loadNavigationFromCache($navigationId)
 {
     return $this->cache->load("nav-{$navigationId}", function (&$dependencies) use($navigationId) {
         $nodes = $this->navigationReader->getEntireNavigation($navigationId);
         return $this->treeBuilder->buildTree($nodes);
     });
 }
开发者ID:blitzik,项目名称:CMS,代码行数:7,代码来源:NavigationFacade.php

示例3: loadEntityConfig

 public function loadEntityConfig($entity, $mergeWithLabelExtensions = TRUE)
 {
     $cacheKey = $entity;
     $cache = new Cache($this->context->cacheStorage, self::CACHE_NAMESPACE);
     $val = $cache->load($cacheKey);
     if ($val === NULL) {
         $params = $this->context->getParameters();
         $configFile = $params['projectDir'] . '/config/entities/' . $entity . '.neon';
         if (!is_file($configFile)) {
             throw new \Nette\FileNotFoundException("Entity config file '{$configFile}' was not found");
         }
         $loader = new Nette\Config\Loader();
         $entityConfig = $loader->load($configFile);
         if ($mergeWithLabelExtensions) {
             $labelProperties = $this->loadLabelExtentsionProperties();
             array_walk($entityConfig['properties'], function (&$item) use($labelProperties) {
                 // if entity params contains reference to ext, expand it
                 if (isset($item['extName'])) {
                     if (isset($labelProperties['properties'][$item['extName']])) {
                         $extParam = $labelProperties['properties'][$item['extName']];
                         $item = array_merge($extParam, $item);
                     }
                 }
             });
         }
         $dp = array(Cache::FILES => array($configFile, CONFIG_DIR . '/labels/labelExtensions.neon', $params['projectDir'] . '/config/labels/labelExtensions.neon'));
         $cache->save($cacheKey, $entityConfig, $dp);
         $val = $entityConfig;
     }
     return $val;
 }
开发者ID:jurasm2,项目名称:bubo,代码行数:31,代码来源:ConfigLoader.php

示例4: actionDefault

 public function actionDefault()
 {
     $cache = new Cache($this->context->cacheStorage, 'Homepage');
     $counts = $cache->load('homepagecounts');
     if ($counts === NULL) {
         $subjectsCount = $this->context->createServicePlaces()->fetchVisible()->count();
         $eventsCount = $this->context->createServiceTimes()->fetchPublic()->group('event_time.event_id')->count();
         $categoriesCount = $this->context->createServiceCategories()->where('subject', '1')->count();
         $counts = array('sc' => $subjectsCount, 'ec' => $eventsCount, 'cc' => $categoriesCount);
         $cache->save('homepagecounts', $counts, array(Cache::EXPIRE => '1 hour', Cache::SLIDING => true, Cache::TAGS => array('event', 'events', 'places', 'place')));
     }
     $this->template->subjectsCount = $counts['sc'];
     $this->template->eventsCount = $counts['ec'];
     $this->template->categoriesCount = $counts['cc'];
     $def = $cache->load('homepagecities');
     if ($def === NULL) {
         $res = Model\Subjects::fetchLocalitiesToCities();
         $cnt = 0;
         foreach ($res as $r) {
             $cnt = $cnt + $r['cnt'];
         }
         $def = array($res, $cnt);
         $cache->save('homepagecities', $def, array('expire' => 100000, 'tags' => 'cities'));
     }
     $this->template->cities = $def[0];
     $this->template->citiesCount = $def[1];
     $this->template->circles = $this->context->createServiceCircles()->order('shift')->where('visible', 1)->limit(4);
 }
开发者ID:soundake,项目名称:pd,代码行数:28,代码来源:HomepagePresenter.php

示例5: addFindConfig

 /**
  * Search configuration files.
  * @param mixed
  * @param mixed
  */
 public function addFindConfig($dirs, $exclude = NULL)
 {
     $cache = new Caching\Cache(new Caching\Storages\FileStorage($this->getCacheDirectory()), self::Caching);
     // Search will be started only when the cache does not exist.
     if (!$cache->load(self::Caching)) {
         // Search configuration files.
         foreach (Utils\Finder::findFiles('*.neon')->from($dirs)->exclude($exclude) as $row) {
             $data[] = $row->getPathname();
         }
         foreach ($data as $row) {
             $name[] = basename($row);
         }
         // Sort found files by number and put into the cache.
         array_multisort($name, SORT_NUMERIC, $data);
         if (isset($data)) {
             $cache->save(self::Caching, $data);
         }
     }
     // Loads the data from the cache.
     if ($cache->load(self::Caching)) {
         foreach ($cache->load(self::Caching) as $files) {
             $this->addConfig($files);
         }
     }
 }
开发者ID:drago-fw,项目名称:drago,代码行数:30,代码来源:Configurator.php

示例6: linkUrls

 /**
  * @param Url $oldUrl
  * @param Url $newUrl
  * @return void
  * @throws \Exception
  */
 public function linkUrls(Url $oldUrl, Url $newUrl)
 {
     if ($oldUrl->getId() === null or $newUrl->getId() === null) {
         throw new UrlNotPersistedException();
     }
     try {
         $this->em->beginTransaction();
         $alreadyRedirectedUrls = $this->findByActualUrl($oldUrl->getId());
         /** @var Url $url */
         foreach ($alreadyRedirectedUrls as $url) {
             $url->setRedirectTo($newUrl);
             $this->em->persist($url);
             $this->cache->clean([Cache::TAGS => [$url->getCacheKey()]]);
         }
         $oldUrl->setRedirectTo($newUrl);
         $this->em->persist($oldUrl);
         $this->cache->clean([Cache::TAGS => [$oldUrl->getCacheKey()]]);
         $this->em->flush();
         $this->em->commit();
     } catch (\Exception $e) {
         $this->em->rollback();
         $this->em->close();
         throw $e;
     }
 }
开发者ID:blitzik,项目名称:CMS,代码行数:31,代码来源:UrlLinker.php

示例7: injectComponentFactories

 /**
  * @param \Nette\DI\Container $dic
  * @throws MemberAccessException
  * @internal
  */
 public function injectComponentFactories(Nette\DI\Container $dic)
 {
     if (!$this instanceof Nette\Application\UI\PresenterComponent && !$this instanceof Nette\Application\UI\Component) {
         throw new MemberAccessException('Trait ' . __TRAIT__ . ' can be used only in descendants of PresenterComponent.');
     }
     $this->autowireComponentFactoriesLocator = $dic;
     $storage = $dic->hasService('autowired.cacheStorage') ? $dic->getService('autowired.cacheStorage') : $dic->getByType('Nette\\Caching\\IStorage');
     $cache = new Nette\Caching\Cache($storage, 'Kdyby.Autowired.AutowireComponentFactories');
     if ($cache->load($presenterClass = get_class($this)) !== NULL) {
         return;
     }
     $ignore = class_parents('Nette\\Application\\UI\\Presenter') + ['ui' => 'Nette\\Application\\UI\\Presenter'];
     $rc = new ClassType($this);
     foreach ($rc->getMethods() as $method) {
         if (in_array($method->getDeclaringClass()->getName(), $ignore, TRUE) || !Strings::startsWith($method->getName(), 'createComponent')) {
             continue;
         }
         foreach ($method->getParameters() as $parameter) {
             if (!($class = $parameter->getClassName())) {
                 // has object type hint
                 continue;
             }
             if (!$this->findByTypeForFactory($class) && !$parameter->allowsNull()) {
                 throw new MissingServiceException("No service of type {$class} found. Make sure the type hint in {$method} is written correctly and service of this type is registered.");
             }
         }
     }
     $files = array_map(function ($class) {
         return ClassType::from($class)->getFileName();
     }, array_diff(array_values(class_parents($presenterClass) + ['me' => $presenterClass]), $ignore));
     $files[] = ClassType::from($this->autowireComponentFactoriesLocator)->getFileName();
     $cache->save($presenterClass, TRUE, [$cache::FILES => $files]);
 }
开发者ID:kdyby,项目名称:autowired,代码行数:38,代码来源:AutowireComponentFactories.php

示例8: render

 /**
  * Renders template to output.
  * @return void
  */
 public function render()
 {
     if ($this->file == NULL) {
         // intentionally ==
         throw new \InvalidStateException("Template file name was not specified.");
     }
     $this->__set('template', $this);
     $shortName = str_replace(dirname(dirname($this->file)), '', $this->file);
     $cache = new Cache($this->getCacheStorage(), 'Nette.FileTemplate');
     $key = trim(strtr($shortName, '\\/@', '.._'), '.') . '-' . md5($this->file);
     $cached = $content = $cache[$key];
     if ($content === NULL) {
         if (!$this->getFilters()) {
             $this->onPrepareFilters($this);
         }
         if (!$this->getFilters()) {
             LimitedScope::load($this->file, $this->getParams());
             return;
         }
         $content = $this->compile(file_get_contents($this->file), "file …{$shortName}");
         $cache->save($key, $content, array(Cache::FILES => $this->file, Cache::EXPIRE => self::$cacheExpire, Cache::CONSTS => 'Nette\\Framework::REVISION'));
         $cache->release();
         $cached = $cache[$key];
     }
     if ($cached !== NULL && self::$cacheStorage instanceof TemplateCacheStorage) {
         LimitedScope::load($cached['file'], $this->getParams());
         fclose($cached['handle']);
     } else {
         LimitedScope::evaluate($content, $this->getParams());
     }
 }
开发者ID:JPalounek,项目名称:IconStore,代码行数:35,代码来源:FileTemplate.php

示例9: render

 /**
  * Renders template to output.
  * @return void
  */
 public function render()
 {
     if ($this->file == NULL) {
         // intentionally ==
         throw new Nette\InvalidStateException('Template file name was not specified.');
     }
     if (!$this->getFilters()) {
         $this->onPrepareFilters($this);
     }
     if ($latte = $this->getLatte()) {
         return $latte->setLoader(new Latte\Loaders\FileLoader())->render($this->file, $this->getParameters());
     }
     $cache = new Caching\Cache($storage = $this->getCacheStorage(), 'Nette.FileTemplate');
     if ($storage instanceof Caching\Storages\PhpFileStorage) {
         $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 (FilterException $e) {
             throw $e->setSource(file_get_contents($this->file), $e->sourceLine, $this->file);
         }
         $cache->save($this->file, $compiled, array(Caching\Cache::FILES => $this->file, Caching\Cache::CONSTS => 'Nette\\Framework::REVISION'));
         $cached = $cache->load($this->file);
     }
     $isFile = $cached !== NULL && $storage instanceof Caching\Storages\PhpFileStorage;
     self::load($isFile ? $cached['file'] : $compiled, $this->getParameters(), $isFile);
 }
开发者ID:petrparolek,项目名称:web_cms,代码行数:33,代码来源:FileTemplate.php

示例10: getClassMetadata

	/**
	 * @param string
	 * @return ClassMetadata
	 * @throws \Nette\InvalidStateException
	 */
	public function getClassMetadata($class)
	{
		$lower = strtolower($class);

		if (isset($this->metas[$lower])) {
			return $this->metas[$lower];
		}

		if ($this->cache && $this->cache[$lower]) {
			return $this->metas[$lower] = $this->cache[$lower];
		}

		if (!class_exists($lower)) {
			throw new \Nette\InvalidArgumentException("Class '$class' not exist");
		}

		$metadata = new ClassMetadata($class);
		foreach ($this->parsers as $parser) {
			$parser->parse($metadata);
		}

		if ($this->cache) {
			$this->cache->save($lower, $metadata, array(
				Cache::FILES => array($metadata->getReflection()->getFileName())
			));
		}

		return $this->metas[$lower] = $metadata;
	}
开发者ID:norbe,项目名称:framework,代码行数:34,代码来源:ClassMetadataFactory.php

示例11: compile

 /**
  * @param Translator $translator
  * @param MessageCatalogueInterface[] $availableCatalogues
  * @param string $locale
  * @throws InvalidArgumentException
  * @return MessageCatalogueInterface|NULL
  */
 public function compile(Translator $translator, array &$availableCatalogues, $locale)
 {
     if (empty($locale)) {
         throw new InvalidArgumentException("Invalid locale.");
     }
     if (isset($availableCatalogues[$locale])) {
         return $availableCatalogues;
     }
     $cacheKey = array($locale, $translator->getFallbackLocales());
     $storage = $this->cache->getStorage();
     if (!$storage instanceof Kdyby\Translation\Caching\PhpFileStorage) {
         if (($messages = $this->cache->load($cacheKey)) !== NULL) {
             $availableCatalogues[$locale] = new MessageCatalogue($locale, $messages);
             return $availableCatalogues;
         }
         $this->catalogueFactory->createCatalogue($translator, $availableCatalogues, $locale);
         $this->cache->save($cacheKey, $availableCatalogues[$locale]->all());
         return $availableCatalogues;
     }
     $storage->hint = $locale;
     $cached = $compiled = $this->cache->load($cacheKey);
     if ($compiled === NULL) {
         $this->catalogueFactory->createCatalogue($translator, $availableCatalogues, $locale);
         $this->cache->save($cacheKey, $compiled = $this->compilePhpCache($translator, $availableCatalogues, $locale));
         $cached = $this->cache->load($cacheKey);
     }
     $availableCatalogues[$locale] = self::load($cached['file']);
     return $availableCatalogues;
 }
开发者ID:tomasstrejcek,项目名称:Translation,代码行数:36,代码来源:CatalogueCompiler.php

示例12: render

 /**
  * Renders template to output.
  *
  * @return void
  */
 public function render()
 {
     if ($this->file == null) {
         // intentionally ==
         throw new Nette\InvalidStateException("Template file name was not specified.");
     }
     $cache = new Caching\Cache($storage = $this->getCacheStorage(), 'Nette.FileTemplate');
     if ($storage instanceof Caching\Storages\PhpFileStorage) {
         $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 (FilterException $e) {
             $e->setSourceFile($this->file);
             throw $e;
         }
         $cache->save($this->file, $compiled, array(Caching\Cache::FILES => $this->file, Caching\Cache::CONSTS => 'Nette\\Framework::REVISION'));
         $cached = $cache->load($this->file);
     }
     if ($cached !== null && $storage instanceof Caching\Storages\PhpFileStorage) {
         Nette\Utils\LimitedScope::load($cached['file'], $this->getParameters());
     } else {
         Nette\Utils\LimitedScope::evaluate($compiled, $this->getParameters());
     }
 }
开发者ID:TheTypoMaster,项目名称:SPHERE-Framework,代码行数:32,代码来源:FileTemplate.php

示例13: createMetaData

 /**
  * Adds support for FQN annotations
  * @param $entityClass
  * @return Orm\MetaData
  */
 public static function createMetaData($entityClass)
 {
     $cache = new Cache(self::$metaDataStorage, __CLASS__);
     return $cache->load($entityClass, function () use($entityClass) {
         return AnnotationMetaData::getMetaData($entityClass);
     });
 }
开发者ID:VasekPurchart,项目名称:khanovaskola-v3,代码行数:12,代码来源:Entity.php

示例14: render

 /**
  * Renders template to output.
  * @return void
  */
 public function render()
 {
     if ($this->file == NULL) {
         // intentionally ==
         throw new \InvalidStateException("Template file name was not specified.");
     }
     $this->__set('template', $this);
     $cache = new Cache($storage = $this->getCacheStorage(), 'Nette.FileTemplate');
     if ($storage instanceof TemplateCacheStorage) {
         $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 (TemplateException $e) {
             $e->setSourceFile($this->file);
             throw $e;
         }
         $cache->save($this->file, $content, array(Cache::FILES => $this->file, Cache::CONSTS => 'Nette\\Framework::REVISION'));
         $cache->release();
         $cached = $cache[$this->file];
     }
     if ($cached !== NULL && $storage instanceof TemplateCacheStorage) {
         LimitedScope::load($cached['file'], $this->getParams());
         flock($cached['handle'], LOCK_UN);
         fclose($cached['handle']);
     } else {
         LimitedScope::evaluate($content, $this->getParams());
     }
 }
开发者ID:JanTvrdik,项目名称:nette,代码行数:36,代码来源:FileTemplate.php

示例15: injectProperties

 /**
  * @param \Nette\DI\Container $dic
  * @throws MemberAccessException
  * @throws MissingServiceException
  * @throws InvalidStateException
  * @throws UnexpectedValueException
  */
 public function injectProperties(Nette\DI\Container $dic)
 {
     if (!$this instanceof Nette\Application\UI\PresenterComponent && !$this instanceof Nette\Application\UI\Component) {
         throw new MemberAccessException('Trait ' . __TRAIT__ . ' can be used only in descendants of PresenterComponent.');
     }
     $this->autowirePropertiesLocator = $dic;
     $storage = $dic->hasService('autowired.cacheStorage') ? $dic->getService('autowired.cacheStorage') : $dic->getByType('Nette\\Caching\\IStorage');
     $cache = new Nette\Caching\Cache($storage, 'Kdyby.Autowired.AutowireProperties');
     $containerFileName = ClassType::from($this->autowirePropertiesLocator)->getFileName();
     $cacheKey = [$presenterClass = get_class($this), $containerFileName];
     if (is_array($this->autowireProperties = $cache->load($cacheKey))) {
         foreach ($this->autowireProperties as $propName => $tmp) {
             unset($this->{$propName});
         }
         return;
     }
     $this->autowireProperties = [];
     $ignore = class_parents('Nette\\Application\\UI\\Presenter') + ['ui' => 'Nette\\Application\\UI\\Presenter'];
     $rc = new ClassType($this);
     foreach ($rc->getProperties() as $prop) {
         if (!$this->validateProperty($prop, $ignore)) {
             continue;
         }
         $this->resolveProperty($prop);
     }
     $files = array_map(function ($class) {
         return ClassType::from($class)->getFileName();
     }, array_diff(array_values(class_parents($presenterClass) + ['me' => $presenterClass]), $ignore));
     $files[] = $containerFileName;
     $cache->save($cacheKey, $this->autowireProperties, [$cache::FILES => $files]);
 }
开发者ID:kdyby,项目名称:autowired,代码行数:38,代码来源:AutowireProperties.php


注:本文中的Nette\Caching\Cache类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。