本文整理汇总了PHP中Zend\Cache\Storage\StorageInterface类的典型用法代码示例。如果您正苦于以下问题:PHP StorageInterface类的具体用法?PHP StorageInterface怎么用?PHP StorageInterface使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StorageInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: it_should_save_parsed_annotations_in_cache
/**
* @param \Zend\Cache\Storage\StorageInterface $cache
*/
public function it_should_save_parsed_annotations_in_cache($cache)
{
// TODO: fix me!
// $cache->hasItem will return ProphecyObject which will always return true in the if.
// Therefore the conditions will be incorrect.
return;
$cache->hasItem('cache-key')->willReturn(false);
$this->mockConfiguration($cache);
$this->getFormSpecification('stdClass');
$cache->setItem('cache-key', Argument::type('ArrayObject'))->shouldHaveBeenCalled();
}
示例2: remove
/**
* @param mixed $key
* @return bool
*/
public function remove($key)
{
if (!$this->isKey($key)) {
$key = $this->createKey($key);
}
return $this->cache->removeItem($key);
}
示例3: 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;
}
示例4: setValue
/**
* Sets or removes value from cache
*
* @param string $name
* @param string $value
* @return void
*/
public function setValue($name, $value = null)
{
if ($value === null) {
$this->container->removeItem($name);
} else {
$this->container->setItem($name, $value);
}
}
示例5: warm
/**
* @param null|array $arguments Must be serializable.
* @return void
*/
public function warm($arguments = null)
{
$callable = $this->callable;
if (is_array($arguments)) {
$value = call_user_func_array($callable, $arguments);
} else {
$value = $callable();
}
$cacheKey = Cache::makeCacheKey($this->name, $arguments);
$this->storage->addItem($cacheKey, serialize($value));
}
示例6: setItems
/**
* Set array of items
* If items already exists, they are replaced
*
* @access public
* @param array $items
*/
public function setItems($items)
{
$existingItemsKeys = array_flip($this->cacheAdapter->hasItems(array_keys($items)));
$existingItems = array_intersect_key($items, $existingItemsKeys);
$nonExistingItems = array_diff_key($items, $existingItemsKeys);
if (count($existingItems) > 0) {
$this->cacheAdapter->replaceItems($existingItems);
}
if (count($nonExistingItems) > 0) {
$this->cacheAdapter->setItems($nonExistingItems);
}
}
示例7: invalidate
/**
* @param Event $e
* @param string $class
* @param string $event
* @return void
*/
public function invalidate(Event $e, $class, $event)
{
$term = $e->getParam('term');
$result = false;
if ($term instanceof TaxonomyTermInterface) {
$result = $this->cacheService->clearByTags(['route_taxonomy/term/get', 'param_term_' . $term->getId()]);
$this->cacheService->clearByTags(['navigation/render']);
$this->clearParents($term);
}
if ($this->storage instanceof FlushableInterface && !$result) {
$this->storage->flush();
}
}
示例8: 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;
}
示例9: invalidate
/**
* @param Event $e
* @param string $class
* @param string $event
* @return void
*/
public function invalidate(Event $e, $class, $event)
{
$repository = $e->getParam('repository');
$result = false;
if ($repository instanceof EntityInterface) {
$result = $this->cacheService->clearByTags(['route_entity/page', 'param_entity_' . $repository->getId()]);
$this->clearTaxonomyTerms($repository->getTaxonomyTerms());
} elseif ($repository instanceof PageRepositoryInterface) {
$result = $this->cacheService->clearByTags(['route_page/view', 'param_page_' . $repository->getId()]);
}
if ($this->storage instanceof FlushableInterface && !$result) {
$this->storage->flush();
}
}
示例10: 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;
}
示例11: 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;
}
示例12: 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'));
}
示例13: save
/**
* Persists a cache item immediately.
*
* @param CacheItemInterface $item
* The cache item to save.
*
* @return bool
* True if the item was successfully persisted. False if there was an error.
*/
public function save(CacheItemInterface $item)
{
if (!$item instanceof CacheItem) {
throw new InvalidArgumentException('$item must be an instance of ' . CacheItem::class);
}
$this->validateKey($item->getKey());
try {
$options = false;
$expiration = $item->getExpiration();
// @todo I can't see any way to set the TTL on an individual item except by temporarily overwriting the
// option on the storage adapter. Not sure if all storage adapters will support this...
if ($expiration instanceof DateTime) {
$options = $this->storage->getOptions();
$new = clone $options;
$interval = $expiration->diff(new DateTime(), true);
$new->setTtl($interval->format('%s'));
$this->storage->setOptions($new);
}
$saved = $this->storage->setItem($item->getKey(), $item->get());
if ($options) {
$this->storage->setOptions($options);
}
} catch (Exception\InvalidArgumentException $e) {
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
} catch (Exception\ExceptionInterface $e) {
throw new CacheException($e->getMessage(), $e->getCode(), $e);
}
return $saved;
}
示例14: 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;
}
示例15: doGetStats
/**
* {@inheritDoc}
*/
protected function doGetStats()
{
/* @var $storage TotalSpaceCapableInterface */
/* @var $storage AvailableSpaceCapableInterface */
$storage = $this->storage;
return array(Cache::STATS_HITS => $this->storage->getMetadata(Cache::STATS_HITS), Cache::STATS_MISSES => $this->storage->getMetadata(Cache::STATS_MISSES), Cache::STATS_UPTIME => $this->storage->getMetadata(Cache::STATS_UPTIME), Cache::STATS_MEMORY_USAGE => $storage instanceof TotalSpaceCapableInterface ? $storage->getTotalSpace() : null, Cache::STATS_MEMORY_AVAILIABLE => $storage instanceof AvailableSpaceCapableInterface ? $storage->getAvailableSpace() : null);
}