本文整理汇总了PHP中Nette\Caching\Cache::load方法的典型用法代码示例。如果您正苦于以下问题:PHP Cache::load方法的具体用法?PHP Cache::load怎么用?PHP Cache::load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Caching\Cache
的用法示例。
在下文中一共展示了Cache::load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: link
/**
* @param string $name
* @return string
*/
public function link($name)
{
$path = $this->cache->load([$name, $this->debugMode]);
$files = $this->files[$name];
$files = is_string($files) ? [$files] : $files;
if ($path === NULL) {
$unpackedFiles = $this->unpack($name, $files);
$time = $this->getModifyTime($unpackedFiles);
$path = $this->genDir . '/' . $this->getOutputFilename($name, $unpackedFiles, $time, $this->debugMode);
$this->cache->save([$name, $this->debugMode], $path);
}
$genFile = "{$this->wwwDir}/{$path}";
if (!file_exists($genFile) || $this->debugMode && filemtime($genFile) < (isset($time) ? $time : ($time = $this->getModifyTime($this->unpack($name, $files))))) {
$start = microtime(TRUE);
$parsedFiles = $this->compile($this->unpack($name, $files), $genFile);
if ($this->debugMode) {
$this->statistics[$name]['time'] = microtime(TRUE) - $start;
$this->statistics[$name]['parsedFiles'] = $parsedFiles;
}
}
if ($this->debugMode) {
$unpackedFiles = $this->unpack($name, $files);
$this->statistics[$name]['size'] = filesize($genFile);
$this->statistics[$name]['file'] = count($unpackedFiles) > 1 ? $unpackedFiles : reset($unpackedFiles);
$this->statistics[$name]['date'] = isset($time) ? $time : ($time = $this->getModifyTime($unpackedFiles));
$this->statistics[$name]['path'] = $path;
}
return $path;
}
示例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);
});
}
示例3: getClass
/**
* @param string $alias
* @param \ReflectionClass $context
* @return string
* @throws Exception\NamespaceNotFoundException
*/
static function getClass($alias, \ReflectionClass $context)
{
if (!strlen($alias)) {
return $alias;
}
if (strncmp($alias, '\\', 1) === 0) {
return substr($alias, 1);
}
$file = $context->getFileName();
if (!isset(self::$map[$file])) {
if (self::$cache === NULL) {
$list = Parser::parse($file);
} else {
$key = self::C_FILE . $file;
$list = self::$cache->load($key);
if ($list === NULL) {
$list = self::$cache->save($key, Parser::parse($file), array(NCache::FILES => array($file)));
}
}
self::$map[$file] = $list;
}
$namespace = $context->getNamespaceName();
if (!isset(self::$map[$file][$namespace])) {
throw new Exception\NamespaceNotFoundException("Namespace '{$namespace}' not found in '{$file}'.");
}
$parts = explode('\\', $alias);
$first = array_shift($parts);
if (!isset(self::$map[$file][$namespace][$first])) {
return ltrim(trim($namespace, '\\') . '\\', '\\') . $alias;
}
$appendix = implode('\\', $parts);
return self::$map[$file][$namespace][$first] . (strlen($appendix) ? '\\' . $appendix : '');
}
示例4: 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());
}
}
示例5: 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);
}
示例6: prepareType
/**
* @param $class
* @param array $types
* @return string
* @throws \Nette\InvalidArgumentException
*/
public function prepareType($class, array $types = array())
{
$class = trim($class, '\\');
$key = serialize(array('class' => $class, 'types' => $types));
if (!isset($this->loaded[$key])) {
$newClass = $this->prepareClassName($class, $types);
if ($this->storage) {
$cache = new Cache($this->storage, 'Venne.Generics');
$data = $cache->load($key);
if (!$data) {
$data = $this->prepareClassTemplate($class, $newClass, $types);
$cache->save($key, $data);
$data = $cache->load($key);
}
if ($this->storage instanceof PhpFileStorage) {
\Nette\Utils\LimitedScope::load($data['file']);
} else {
\Nette\Utils\LimitedScope::evaluate($data);
}
} else {
$data = $this->prepareClassTemplate($class, $newClass, $types);
\Nette\Utils\LimitedScope::evaluate($data);
}
$this->loaded[$key] = $newClass;
}
return $this->loaded[$key];
}
示例7: 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);
}
示例8: findEventsByType
public function findEventsByType($logTypeID)
{
return $this->cache->load('logEvents-' . $logTypeID, function (&$dependencies) use($logTypeID) {
return array_column($this->em->createQuery('SELECT e.id, e.name FROM ' . EventLog::class . ' e INDEX BY e.id
WHERE e.logType = :typeID')->setParameter('typeID', $logTypeID)->getArrayResult(), 'name', 'id');
});
}
示例9: build
public function build(array $nodes = NULL)
{
if (!$this->built) {
$key = sprintf('nodes-%d', $this->language->getCurrent()->id);
if ($this->cache->load($key) === NULL) {
$rows = $this->repository->findAll();
$nodes = [];
$parents = [];
$children = [];
foreach ($rows as $node) {
$this->onFetch($node);
$nodes[$node->id] = json_encode($node);
if ($node->parent === NULL) {
$parents[$node->order] = $node->id;
} else {
$children[$node->parent->id][$node->order] = $node->id;
}
}
$this->cache->save($key, [$nodes, $parents, $children], [Cache::TAGS => [get_called_class()]]);
}
list($nodes, $this->parents, $this->children) = $this->cache->load($key);
foreach ($nodes as $node) {
$node = $this->repository->createUnserializedEntity($node);
$this->nodes[$node->id] = $node;
$this->urls[$node->url] = $node->id;
if ($node->root) {
$this->root = $node;
}
}
$this->onBuild();
$this->built = true;
}
}
示例10: 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;
}
示例11: 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);
}
}
}
示例12: load
public function load($key, $callback)
{
return $this->cache->load($key, function (&$dependencies) use($callback) {
$dependencies = $this->dependencies;
return call_user_func($callback);
});
}
示例13: setConnection
public function setConnection(Nette\Database\Connection $connection)
{
$this->connection = $connection;
if ($this->cacheStorage) {
$this->cache = new Nette\Caching\Cache($this->cacheStorage, 'Nette.Database.' . md5($connection->getDsn()));
$this->structure = $this->cache->load('structure') ?: $this->structure;
}
}
示例14: loadCachedNamespace
/**
* @param $namespace
* @return array
*/
public function loadCachedNamespace($namespace)
{
if (isset($this->loadedData[$namespace])) {
return $this->loadedData[$namespace];
} else {
return $this->loadedData[$namespace] = $this->cache->load($namespace);
}
}
示例15: load
/**
* @param string
* @return mixed|NULL
*/
public function load($key)
{
$cached = $this->cache->load($key);
if (!is_array($cached) || $cached[1] !== $this->expire) {
return NULL;
}
return $cached[0];
}