/** * @param mixed $key * @return bool */ public function remove($key) { if (!$this->isKey($key)) { $key = $this->createKey($key); } return $this->cache->removeItem($key); }
/** * 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); } }
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; }
/** * 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; }
/** * 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)); }
/** * 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; }
/** * 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); } } }
/** * @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); }
/** * 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; }
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; } }
/** * 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; }
/** * 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; }
public function testRemoveItemReturnsFalseOnMissingItem() { $this->assertFalse($this->_storage->removeItem('missing')); }
public function purge($url) { return $this->storageCache->removeItem($this->buildKey($url)); }
/** * {@inheritDoc} */ public function remove($key) { return $this->zendCache->removeItem($key); }
/** * @since 1.1 * * {@inheritDoc} */ public function delete($id) { $this->cacheDeletes++; return $this->cache->removeItem($id); }
/** * {@inheritDoc} */ protected function doDelete($id) { return $this->storage->removeItem($id); }
/** * @param $cacheKey */ public function delItem($cacheKey) { $this->cachingService->removeItem($cacheKey); }