本文整理汇总了PHP中Zend\Cache\Storage\StorageInterface::removeItem方法的典型用法代码示例。如果您正苦于以下问题:PHP StorageInterface::removeItem方法的具体用法?PHP StorageInterface::removeItem怎么用?PHP StorageInterface::removeItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Cache\Storage\StorageInterface
的用法示例。
在下文中一共展示了StorageInterface::removeItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: remove
/**
* @param mixed $key
* @return bool
*/
public function remove($key)
{
if (!$this->isKey($key)) {
$key = $this->createKey($key);
}
return $this->cache->removeItem($key);
}
示例2: 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);
}
}
示例3: setDelayedItem
public function setDelayedItem($key, Closure $closure)
{
$this->storage->setItem($this->getDelayedKey($key), self::UNDER_CONSTRUCTION_VALUE);
$setReturn = $this->storage->setItem($key, $closure());
$this->storage->removeItem($this->getDelayedKey($key));
return $setReturn;
}
示例4: callWidget
/**
* Call widget
*
* @param string $position
* @param integer $pageId
* @param integer $userRole
* @param array $widgetInfo
* @param boolean $useLayout
* @throws \Page\Exception\PageException
* @return string|boolean
*/
protected function callWidget($position, $pageId, $userRole, array $widgetInfo, $useLayout = true)
{
// don't call any widgets
if (true === self::$widgetRedirected) {
return false;
}
// check a widget visibility
if ($userRole != AclBaseModel::DEFAULT_ROLE_ADMIN) {
if (!empty($widgetInfo['hidden']) && in_array($userRole, $widgetInfo['hidden'])) {
return false;
}
}
// call the widget
$widget = $this->getView()->{$widgetInfo['widget_name']}();
// check the widget
if (!$widget instanceof IPageWidget) {
throw new PageException(sprintf($widgetInfo['widget_name'] . ' must be an object implementing IPageWidget'));
}
// init the widget
$widget->setPageId($pageId)->setWidgetPosition($position)->setWidgetConnectionId($widgetInfo['widget_connection_id']);
$widgetCacheName = null;
if ((int) $widgetInfo['widget_cache_ttl']) {
// generate a cache name
$widgetCacheName = CacheUtility::getCacheName($widgetInfo['widget_name'], [$widgetInfo['widget_connection_id']]);
// check the widget data in a cache
if (null !== ($cachedWidgetData = $this->dynamicCache->getItem($widgetCacheName))) {
// check a local widget lifetime
if ($cachedWidgetData['widget_expire'] >= time()) {
// include widget's css and js files
if (false !== $cachedWidgetData['widget_content'] && !$this->request->isXmlHttpRequest()) {
$widget->includeJsCssFiles();
}
return $cachedWidgetData['widget_content'];
}
// clear cache
$this->dynamicCache->removeItem($widgetCacheName);
}
}
if (false !== ($widgetContent = $widget->getContent())) {
self::$widgetRedirected = $widget->isWidgetRedirected();
// include widget's css and js files
if (!$this->request->isXmlHttpRequest()) {
$widget->includeJsCssFiles();
}
// add the widget's layout
if ($useLayout) {
if (!empty($widgetInfo['widget_layout'])) {
$widgetContent = $this->getView()->partial($this->layoutPath . $widgetInfo['widget_layout'], ['title' => $this->getView()->pageWidgetTitle($widgetInfo), 'content' => $widgetContent]);
} else {
$widgetContent = $this->getView()->partial($this->layoutPath . 'default', ['title' => $this->getView()->pageWidgetTitle($widgetInfo), 'content' => $widgetContent]);
}
}
}
// cache the widget data
if ($widgetCacheName) {
$this->dynamicCache->setItem($widgetCacheName, ['widget_content' => $widgetContent, 'widget_expire' => time() + $widgetInfo['widget_cache_ttl']]);
}
return $widgetContent;
}
示例5: removeCachedData
/**
* Helper function for removing cached data.
*
* @param string $key Cache entry key
*
* @return void
*/
protected function removeCachedData($key)
{
// Don't write to cache if we don't have a cache!
if (null === $this->cache) {
return;
}
$this->cache->removeItem($this->formatCacheKey($key));
}
示例6: releaseLock
/**
* Release lock
*
* @param string $name name of lock
* @return bool
*/
public function releaseLock($name)
{
if (isset($this->locks[$name])) {
$this->cache->removeItem($name);
return true;
}
return false;
}
示例7: onKernelRequest
/**
* Triggered before controller call
*
* @param GetResponseEvent $event
*/
public function onKernelRequest(GetResponseEvent $event)
{
$request = $event->getRequest();
if ($event->getRequestType() === HttpKernelInterface::MASTER_REQUEST && $request->isMethodSafe()) {
$key = $this->getKeyFromRequest($request);
// If no cache request header exists - clear cache
if ($request->isNoCache()) {
$this->storage->removeItem($key);
}
// If response exists in cache - restore it and set back to event
if ($this->storage->hasItem($key)) {
$data = $this->storage->getItem($key);
$response = new Response($data['content'], $data['status'], $data['headers']);
$response->prepare($request);
$response->isNotModified($request);
$event->setResponse($response);
}
}
}
示例8: canSetDelayedItemReturnsAdapter
/**
* @test
*/
public function canSetDelayedItemReturnsAdapter()
{
$this->storage->setItem($this->delayedKey, 'under_construction')->shouldBeCalled();
$this->storage->removeItem($this->delayedKey)->shouldBeCalled();
$this->storage->setItem('foo', 'bar')->willReturn(true);
$return = $this->cache->setDelayedItem('foo', function () {
return 'bar';
});
$this->assertSame(true, $return);
}
示例9: deleteItem
/**
* Removes the item from the pool.
*
* @param string $key
* The key for which to delete
*
* @throws InvalidArgumentException
* If the $key string is not a legal value a \Psr\Cache\InvalidArgumentException
* MUST be thrown.
*
* @return bool
* True if the item was successfully removed. False if there was an error.
*/
public function deleteItem($key)
{
$this->validateKey($key);
try {
$deleted = $this->storage->removeItem($key);
} 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 $deleted;
}
示例10: setDelayedItem
public function setDelayedItem($key, Closure $closure)
{
try {
$delayedKey = $this->getDelayedKey($key);
$this->storage->setItem($this->getDelayedKey($key), self::UNDER_CONSTRUCTION_VALUE);
$setReturn = $this->storage->setItem($key, $closure());
$this->storage->removeItem($delayedKey);
return $setReturn;
} catch (\Exception $exception) {
$this->storage->removeItem($delayedKey);
throw $exception;
}
}
示例11: getCachedData
/**
* Helper function for fetching cached data.
* Data is cached for up to $this->cacheLifetime seconds so that it would be
* faster to process e.g. requests where multiple calls to the backend are made.
*
* @param string $key Cache entry key
*
* @return mixed|null Cached entry or null if not cached or expired
*/
protected function getCachedData($key)
{
// No cache object, no cached results!
if (null === $this->cache) {
return null;
}
$fullKey = $this->formatCacheKey($key);
$item = $this->cache->getItem($fullKey);
if (null !== $item) {
// Return value if still valid:
if (time() - $item['time'] < $this->cacheLifetime) {
return $item['entry'];
}
// Clear expired item from cache:
$this->cache->removeItem($fullKey);
}
return null;
}
示例12: clearPageItemCache
/**
* Clear the page item cache.
*
* @param int $pageNumber
* @return Paginator
*/
public function clearPageItemCache($pageNumber = null)
{
if (!$this->cacheEnabled()) {
return $this;
}
if (null === $pageNumber) {
$prefixLength = strlen(self::CACHE_TAG_PREFIX);
$cacheIterator = static::$cache->getIterator();
$cacheIterator->setMode(CacheIterator::CURRENT_AS_KEY);
foreach ($cacheIterator as $key) {
if (substr($key, 0, $prefixLength) == self::CACHE_TAG_PREFIX) {
static::$cache->removeItem($this->_getCacheId((int) substr($key, $prefixLength)));
}
}
} else {
$cleanId = $this->_getCacheId($pageNumber);
static::$cache->removeItem($cleanId);
}
return $this;
}
示例13: testRemoveItemReturnsFalseOnMissingItem
public function testRemoveItemReturnsFalseOnMissingItem()
{
$this->assertFalse($this->_storage->removeItem('missing'));
}
示例14: purge
public function purge($url)
{
return $this->storageCache->removeItem($this->buildKey($url));
}
示例15: remove
/**
* {@inheritDoc}
*/
public function remove($key)
{
return $this->zendCache->removeItem($key);
}