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


PHP StorageInterface::hasItem方法代码示例

本文整理汇总了PHP中Zend\Cache\Storage\StorageInterface::hasItem方法的典型用法代码示例。如果您正苦于以下问题:PHP StorageInterface::hasItem方法的具体用法?PHP StorageInterface::hasItem怎么用?PHP StorageInterface::hasItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Cache\Storage\StorageInterface的用法示例。


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

示例1: has

 /**
  * @param mixed$key
  * @return bool
  */
 public function has($key)
 {
     if (!$this->isKey($key)) {
         $key = $this->createKey($key);
     }
     return $this->cache->hasItem($key);
 }
开发者ID:lazhacks,项目名称:h2-zex-common,代码行数:11,代码来源:RedisCache.php

示例2: provide

 public function provide($container)
 {
     $instance = $this->instanceManager->getInstanceFromRequest();
     $pages = [];
     try {
         $container = $this->navigationManager->findContainerByNameAndInstance($container, $instance);
     } catch (ContainerNotFoundException $e) {
         return [];
     }
     $key = hash('sha256', serialize($container));
     if ($this->storage->hasItem($key)) {
         return $this->storage->getItem($key);
     }
     foreach ($container->getPages() as $page) {
         $addPage = $this->buildPage($page);
         $hasUri = isset($addPage['uri']);
         $hasMvc = isset($addPage['action']) || isset($addPage['controller']) || isset($addPage['route']);
         $hasProvider = isset($addPage['provider']);
         if ($hasUri || $hasMvc || $hasProvider) {
             $pages[] = $addPage;
         }
     }
     $this->storage->setItem($key, $pages);
     return $pages;
 }
开发者ID:andreas-serlo,项目名称:athene2,代码行数:25,代码来源:ContainerRepositoryProvider.php

示例3: getValue

 /**
  * @param  null|array $arguments Must be serializable.
  * @return mixed
  */
 public function getValue($arguments = null)
 {
     $cacheKey = Cache::makeCacheKey($this->name, $arguments);
     if (!$this->storage->hasItem($cacheKey)) {
         $this->warm($arguments);
     }
     return unserialize($this->storage->getItem($cacheKey));
 }
开发者ID:drcts,项目名称:closure-cache,代码行数:12,代码来源:Operation.php

示例4: setItem

 /**
  * Set key with value
  * If item already exists, it is replaced
  * 
  * @access public
  * @param string $key
  * @param string $value
  */
 public function setItem($key, $value)
 {
     if ($this->cacheAdapter->hasItem($key)) {
         $methodName = "replaceItem";
     } else {
         $methodName = "setItem";
     }
     $this->cacheAdapter->{$methodName}($key, $value);
 }
开发者ID:camelcasetechsd,项目名称:certigate,代码行数:17,代码来源:Cache.php

示例5: getResult

 protected function getResult()
 {
     if ($this->cache->hasItem('result')) {
         return $this->cache->getItem('result');
     }
     // The bellow code do not work with zend
     // $this->cache->setItem('result', $this->calculation);
     // $result = $this->cache->getItem('result');
     $calculation = $this->calculation;
     $result = $calculation();
     $this->cache->setItem('result', $result);
     return $result;
 }
开发者ID:koinephp,项目名称:DelayedCache,代码行数:13,代码来源:RegularCache.php

示例6: load

 /**
  * Check if a page is saved in the cache and return contents.
  * Return null when no item is found.
  *
  * @param MvcEvent $e Mvc Event
  *
  * @return mixed
  */
 public function load(MvcEvent $e)
 {
     $id = $this->createId($e->getRequest());
     if (!$this->cacheStorage->hasItem($id)) {
         return null;
     }
     $event = new CacheEvent(CacheEvent::EVENT_LOAD, $this);
     $event->setCacheKey($id);
     $this->getEventManager()->trigger($event);
     if ($event->getAbort()) {
         return null;
     }
     return $this->cacheStorage->getItem($id);
 }
开发者ID:gotcms,项目名称:gotcms,代码行数:22,代码来源:CacheService.php

示例7: getUnrevisedRevisions

 public function getUnrevisedRevisions(TaxonomyTermInterface $term)
 {
     $key = hash('sha256', serialize($term));
     if ($this->storage->hasItem($key)) {
         return $this->storage->getItem($key);
     }
     $entities = $this->getEntities($term);
     $collection = new ArrayCollection();
     $this->iterEntities($entities, $collection, 'isRevised');
     $iterator = $collection->getIterator();
     $iterator->ksort();
     $collection = new ArrayCollection(iterator_to_array($iterator));
     $this->storage->setItem($key, $collection);
     return $collection;
 }
开发者ID:andreas-serlo,项目名称:athene2,代码行数:15,代码来源:SubjectManager.php

示例8: render

 public function render($limit = 25)
 {
     $user = $this->userManager->getUserFromAuthenticator();
     $key = hash('sha256', serialize($user));
     $output = '';
     if ($this->storage->hasItem($key)) {
         //return $this->storage->getItem($key);
     }
     if ($user) {
         $notifications = $this->notificationManager->findNotificationsBySubscriber($user, $limit);
         $output = $this->renderer->render($this->template, ['notifications' => $notifications]);
         $this->storage->setItem($key, $output);
     }
     return $output;
 }
开发者ID:andreas-serlo,项目名称:athene2,代码行数:15,代码来源:Notification.php

示例9: testTaggable

 public function testTaggable()
 {
     if (!$this->_storage instanceof TaggableInterface) {
         $this->markTestSkipped("Storage doesn't implement TaggableInterface");
     }
     // store 3 items and register the current default namespace
     $this->assertSame([], $this->_storage->setItems(['key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3']));
     $this->assertTrue($this->_storage->setTags('key1', ['tag1a', 'tag1b']));
     $this->assertTrue($this->_storage->setTags('key2', ['tag2a', 'tag2b']));
     $this->assertTrue($this->_storage->setTags('key3', ['tag3a', 'tag3b']));
     $this->assertFalse($this->_storage->setTags('missing', ['tag']));
     // return tags
     $tags = $this->_storage->getTags('key1');
     $this->assertInternalType('array', $tags);
     sort($tags);
     $this->assertSame(['tag1a', 'tag1b'], $tags);
     // this should remove nothing
     $this->assertTrue($this->_storage->clearByTags(['tag1a', 'tag2a']));
     $this->assertTrue($this->_storage->hasItem('key1'));
     $this->assertTrue($this->_storage->hasItem('key2'));
     $this->assertTrue($this->_storage->hasItem('key3'));
     // this should remove key1 and key2
     $this->assertTrue($this->_storage->clearByTags(['tag1a', 'tag2b'], true));
     $this->assertFalse($this->_storage->hasItem('key1'));
     $this->assertFalse($this->_storage->hasItem('key2'));
     $this->assertTrue($this->_storage->hasItem('key3'));
     // this should remove key3
     $this->assertTrue($this->_storage->clearByTags(['tag3a', 'tag3b'], true));
     $this->assertFalse($this->_storage->hasItem('key1'));
     $this->assertFalse($this->_storage->hasItem('key2'));
     $this->assertFalse($this->_storage->hasItem('key3'));
 }
开发者ID:MehrAlsNix,项目名称:zf-couchbase2,代码行数:32,代码来源:CommonAdapterTest.php

示例10: testTagable

 public function testTagable()
 {
     if (!$this->_storage instanceof TaggableInterface) {
         $this->markTestSkipped("Storage doesn't implement TaggableInterface");
     }
     $this->assertSame(array(), $this->_storage->setItems(array('key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3')));
     $this->assertTrue($this->_storage->setTags('key1', array('tag1a', 'tag1b')));
     $this->assertTrue($this->_storage->setTags('key2', array('tag2a', 'tag2b')));
     $this->assertTrue($this->_storage->setTags('key3', array('tag3a', 'tag3b')));
     $this->assertFalse($this->_storage->setTags('missing', array('tag')));
     // return tags
     $tags = $this->_storage->getTags('key1');
     $this->assertInternalType('array', $tags);
     sort($tags);
     $this->assertSame(array('tag1a', 'tag1b'), $tags);
     // this should remove nothing
     $this->assertTrue($this->_storage->clearByTags(array('tag1a', 'tag2a')));
     $this->assertTrue($this->_storage->hasItem('key1'));
     $this->assertTrue($this->_storage->hasItem('key2'));
     $this->assertTrue($this->_storage->hasItem('key3'));
     // this should remove key1 and key2
     $this->assertTrue($this->_storage->clearByTags(array('tag1a', 'tag2b'), true));
     $this->assertFalse($this->_storage->hasItem('key1'));
     $this->assertFalse($this->_storage->hasItem('key2'));
     $this->assertTrue($this->_storage->hasItem('key3'));
     // this should remove key3
     $this->assertTrue($this->_storage->clearByTags(array('tag3a', 'tag3b'), true));
     $this->assertFalse($this->_storage->hasItem('key1'));
     $this->assertFalse($this->_storage->hasItem('key2'));
     $this->assertFalse($this->_storage->hasItem('key3'));
 }
开发者ID:ninahuanca,项目名称:zf2,代码行数:31,代码来源:CommonAdapterTest.php

示例11: findSourceByAlias

 public function findSourceByAlias($alias, $useCache = false)
 {
     if (!is_string($alias)) {
         throw new Exception\InvalidArgumentException(sprintf('Expected alias to be string but got "%s"', gettype($alias)));
     }
     $key = 'source:by:alias:' . $alias;
     if ($useCache && $this->storage->hasItem($key)) {
         // The item is null so it didn't get found.
         $item = $this->storage->getItem($key);
         if ($item === self::CACHE_NONEXISTENT) {
             throw new Exception\AliasNotFoundException(sprintf('Alias `%s` not found.', $alias));
         }
         return $item;
     }
     /* @var $entity Entity\AliasInterface */
     $criteria = ['alias' => $alias];
     $order = ['timestamp' => 'DESC'];
     $results = $this->getAliasRepository()->findBy($criteria, $order);
     $entity = current($results);
     if (!is_object($entity)) {
         $this->storage->setItem($key, self::CACHE_NONEXISTENT);
         throw new Exception\AliasNotFoundException(sprintf('Alias `%s` not found.', $alias));
     }
     $source = $entity->getSource();
     if ($useCache) {
         $this->storage->setItem($key, $source);
     }
     return $source;
 }
开发者ID:andreas-serlo,项目名称:athene2,代码行数:29,代码来源:AliasManager.php

示例12: getPluginByInstanceId

 /**
  * Get a plugin by instance Id
  *
  * @param integer $pluginInstanceId Plugin Instance Id
  *
  * @return array|mixed
  * @throws \Rcm\Exception\PluginInstanceNotFoundException
  * @deprecated
  */
 public function getPluginByInstanceId($pluginInstanceId)
 {
     $cacheId = 'rcmPluginInstance_' . $pluginInstanceId;
     if ($this->cache->hasItem($cacheId)) {
         $return = $this->cache->getItem($cacheId);
         $return['fromCache'] = true;
         return $return;
     }
     $pluginInstance = $this->getInstanceEntity($pluginInstanceId);
     if (empty($pluginInstance)) {
         throw new PluginInstanceNotFoundException('Plugin for instance id ' . $pluginInstanceId . ' not found.');
     }
     $instanceConfig = $this->getInstanceConfigFromEntity($pluginInstance);
     $return = $this->getPluginViewData($pluginInstance->getPlugin(), $pluginInstanceId, $instanceConfig);
     if ($pluginInstance->isSiteWide()) {
         $return['siteWide'] = true;
         $displayName = $pluginInstance->getDisplayName();
         if (!empty($displayName)) {
             $return['displayName'] = $displayName;
         }
     }
     $return['md5'] = $pluginInstance->getMd5();
     if ($return['canCache']) {
         $this->cache->setItem($cacheId, $return);
     }
     return $return;
 }
开发者ID:reliv,项目名称:rcm,代码行数:36,代码来源:PluginManager.php

示例13: testReplaceItemsReturnsFailedKeys

 public function testReplaceItemsReturnsFailedKeys()
 {
     $this->assertTrue($this->_storage->setItem('key1', 'value1'));
     $failedKeys = $this->_storage->replaceItems(array('key1' => 'XYZ', 'key2' => 'value2'));
     $this->assertSame(array('key2'), $failedKeys);
     $this->assertSame('XYZ', $this->_storage->getItem('key1'));
     $this->assertFalse($this->_storage->hasItem('key2'));
 }
开发者ID:antoinealej,项目名称:HomeStuff,代码行数:8,代码来源:DoctrineCacheStorageTest.php

示例14: getThumbnail

 /**
  *
  * @param string $filename
  * @param \Soluble\Media\BoxDimension $box
  * @param string $format
  * @param int $quality
  * @throws \Soluble\Media\Converter\Exception
  * @throws \Exception
  */
 public function getThumbnail($filename, BoxDimension $box, $format = null, $quality = null)
 {
     $width = $box->getWidth();
     $height = $box->getHeight();
     if ($quality === null) {
         $quality = $this->default_quality;
     }
     $cache_key = md5("{$filename}/{$width}/{$height}/{$quality}/{$format}");
     if ($this->cacheEnabled && $this->cacheStorage->hasItem($cache_key)) {
         $cacheMd = $this->cacheStorage->getMetadata($cache_key);
         if ($cacheMd['mtime'] < filemtime($filename)) {
             // invalid cache
             $binaryContent = $this->generateThumbnail($filename, $box, $format, $quality);
             $this->cacheStorage->setItem($cache_key, $binaryContent);
         } else {
             $binaryContent = $this->cacheStorage->getItem($cache_key);
         }
     } else {
         $binaryContent = $this->generateThumbnail($filename, $box, $format, $quality);
         $this->cacheStorage->setItem($cache_key, $binaryContent);
     }
     switch ($format) {
         case 'jpg':
             $content_type = 'image/jpeg';
             break;
         case 'png':
             $content_type = 'image/png';
             break;
         case 'gif':
             $content_type = 'image/gif';
             break;
         default:
             throw new \Exception("Unsupported format '{$format}'");
     }
     header("Content-type: {$content_type}", true);
     header("Accept-Ranges: bytes", true);
     header("Cache-control: max-age=2592000, public", true);
     header("Content-Disposition: inline; filename=\"{$filename}\";", true);
     header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($filename)) . ' GMT', true);
     header('Expires: ' . gmdate('D, d M Y H:i:s', strtotime('+1 years')) . ' GMT', true);
     //header('Content-Disposition: attachment; filename="downloaded.pdf"');
     header('Pragma: cache', true);
     echo $binaryContent;
     die;
 }
开发者ID:robocoder,项目名称:solublecomponents,代码行数:54,代码来源:ImageConverter.php

示例15: provide

 /**
  * @param array $options
  * @return array
  */
 public function provide(array $options)
 {
     $this->options = ArrayUtils::merge($this->defaultOptions, $options);
     $key = hash('sha256', serialize($this->options));
     $this->options['types'] = ArrayUtils::merge($this->options['types'], $this->options['hidden']);
     if ($this->storage->hasItem($key)) {
         return $this->storage->getItem($key);
     }
     $term = $this->getTerm();
     if ($this->getObjectManager()->isOpen()) {
         $this->getObjectManager()->refresh($term);
     }
     $terms = $term->findChildrenByTaxonomyNames($this->options['types']);
     $pages = $this->iterTerms($terms, $this->options['max_depth']);
     $this->term = null;
     $this->storage->setItem($key, $pages);
     return $pages;
 }
开发者ID:andreas-serlo,项目名称:athene2,代码行数:22,代码来源:NavigationProvider.php


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