本文整理汇总了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);
}
示例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;
}
示例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));
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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'));
}
示例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'));
}
示例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;
}
示例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;
}
示例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'));
}
示例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;
}
示例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;
}