コード例 #1
0
ファイル: RedisCache.php プロジェクト: lazhacks/h2-zex-common
 /**
  * @param mixed $key
  * @return bool
  */
 public function remove($key)
 {
     if (!$this->isKey($key)) {
         $key = $this->createKey($key);
     }
     return $this->cache->removeItem($key);
 }
コード例 #2
0
 /**
  * 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
0
 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
0
ファイル: PageInjectWidget.php プロジェクト: esase/dream-cms
 /**
  * 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
0
ファイル: AbstractBase.php プロジェクト: datavoyager/vufind
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * @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
0
 /**
  * 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
0
 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
0
ファイル: AbstractBase.php プロジェクト: grharry/vufind
 /**
  * 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
0
ファイル: Paginator.php プロジェクト: robertboloc/zf2
 /**
  * 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
0
ファイル: CommonAdapterTest.php プロジェクト: ninahuanca/zf2
 public function testRemoveItemReturnsFalseOnMissingItem()
 {
     $this->assertFalse($this->_storage->removeItem('missing'));
 }
コード例 #14
0
 public function purge($url)
 {
     return $this->storageCache->removeItem($this->buildKey($url));
 }
コード例 #15
0
 /**
  * {@inheritDoc}
  */
 public function remove($key)
 {
     return $this->zendCache->removeItem($key);
 }
コード例 #16
0
ファイル: ZendCache.php プロジェクト: Rikuforever/wiki
 /**
  * @since 1.1
  *
  * {@inheritDoc}
  */
 public function delete($id)
 {
     $this->cacheDeletes++;
     return $this->cache->removeItem($id);
 }
コード例 #17
0
 /**
  * {@inheritDoc}
  */
 protected function doDelete($id)
 {
     return $this->storage->removeItem($id);
 }
コード例 #18
0
 /**
  * @param $cacheKey
  */
 public function delItem($cacheKey)
 {
     $this->cachingService->removeItem($cacheKey);
 }