Example #1
0
 /**
  * @test
  */
 public function getOnSecondaryCacheIsNeverCalledWhenValueIsPresentInFirstLevelCache()
 {
     $this->secondLevelCacheMock->expects($this->never())->method('get');
     // when we add a value with the identifier to the two level cache, the second level
     // cache should not be asked because the value should allready be found in the first
     // level cache
     $this->twoLevelCache->set('foo', 'bar');
     $value = $this->twoLevelCache->get('foo');
     $this->assertSame($value, 'bar', 'Did not get expected value from two level cache');
 }
Example #2
0
 /**
  * Actual function to generate the rootline and cache it
  *
  * @throws \RuntimeException
  * @return void
  */
 protected function generateRootlineCache()
 {
     $page = $this->getRecordArray($this->pageUid);
     // If the current page is a mounted (according to the MP parameter) handle the mount-point
     if ($this->isMountedPage()) {
         $mountPoint = $this->getRecordArray($this->parsedMountPointParameters[$this->pageUid]);
         $page = $this->processMountedPage($page, $mountPoint);
         $parentUid = $mountPoint['pid'];
         // Anyhow after reaching the mount-point, we have to go up that rootline
         unset($this->parsedMountPointParameters[$this->pageUid]);
     } else {
         $parentUid = $page['pid'];
     }
     $cacheTags = array('pageId_' . $page['uid']);
     if ($parentUid > 0) {
         // Get rootline of (and including) parent page
         $mountPointParameter = !empty($this->parsedMountPointParameters) ? $this->mountPointParameter : '';
         /** @var $rootline \TYPO3\CMS\Core\Utility\RootlineUtility */
         $rootline = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Utility\RootlineUtility::class, $parentUid, $mountPointParameter, $this->pageContext);
         $rootline = $rootline->get();
         // retrieve cache tags of parent rootline
         foreach ($rootline as $entry) {
             $cacheTags[] = 'pageId_' . $entry['uid'];
             if ($entry['uid'] == $this->pageUid) {
                 throw new \RuntimeException('Circular connection in rootline for page with uid ' . $this->pageUid . ' found. Check your mountpoint configuration.', 1343464103);
             }
         }
     } else {
         $rootline = array();
     }
     array_push($rootline, $page);
     krsort($rootline);
     static::$cache->set($this->cacheIdentifier, $rootline, $cacheTags);
     static::$localCache[$this->cacheIdentifier] = $rootline;
 }
Example #3
0
 /**
  * Returns banners for the given parameters if given Hmac validation succeeds
  *
  * @param string $categories
  * @param string $startingPoint
  * @param string $displayMode
  * @param int $currentPageUid
  * @param string $hmac
  * @return string
  */
 public function getBannersAction($categories = '', $startingPoint = '', $displayMode = 'all', $currentPageUid = 0, $hmac = '')
 {
     $compareString = $currentPageUid . $categories . $startingPoint . $displayMode;
     if ($this->hashService->validateHmac($compareString, $hmac)) {
         /** @var \DERHANSEN\SfBanners\Domain\Model\BannerDemand $demand */
         $demand = $this->objectManager->get('DERHANSEN\\SfBanners\\Domain\\Model\\BannerDemand');
         $demand->setCategories($categories);
         $demand->setStartingPoint($startingPoint);
         $demand->setDisplayMode($displayMode);
         $demand->setCurrentPageUid($currentPageUid);
         /* Get banners */
         $banners = $this->bannerRepository->findDemanded($demand);
         /* Update Impressions */
         $this->bannerRepository->updateImpressions($banners);
         /* Collect identifier based on uids for all banners */
         $ident = $GLOBALS['TSFE']->id . $GLOBALS['TSFE']->sys_language_uid;
         foreach ($banners as $banner) {
             $ident .= $banner->getUid();
         }
         $ret = $this->cacheInstance->get(sha1($ident));
         if ($ret === false || $ret === null) {
             $this->view->assign('banners', $banners);
             $this->view->assign('settings', $this->settings);
             $ret = $this->view->render();
             // Save value in cache
             $this->cacheInstance->set(sha1($ident), $ret, array('sf_banners'), $this->settings['cacheLifetime']);
         }
     } else {
         $ret = LocalizationUtility::translate('wrong_hmac', 'SfBanners');
     }
     return $ret;
 }
 /**
  * Complete password reset
  *
  * @param string $hash Identification hash of a password reset token
  * @param string $password New password of the user
  * @param string $passwordRepeat Confirmation of the new password
  * @return void
  *
  * @validate $password NotEmpty
  * @validate $passwordRepeat NotEmpty
  */
 public function completePasswordResetAction($hash, $password, $passwordRepeat)
 {
     $token = $this->tokenCache->get($hash);
     if ($token !== FALSE) {
         $user = $this->frontendUserRepository->findByIdentifier($token['uid']);
         if ($user !== NULL) {
             if ($this->hashService->validateHmac($user->getPassword(), $token['hmac'])) {
                 $user->setPassword($this->passwordService->applyTransformations($password));
                 $this->frontendUserRepository->update($user);
                 $this->tokenCache->remove($hash);
                 if ($this->getSettingValue('passwordReset.loginOnSuccess')) {
                     $this->authenticationService->authenticateUser($user);
                     $this->addLocalizedFlashMessage('resetPassword.completed.login', NULL, FlashMessage::OK);
                 } else {
                     $this->addLocalizedFlashMessage('resetPassword.completed', NULL, FlashMessage::OK);
                 }
             } else {
                 $this->addLocalizedFlashMessage('resetPassword.failed.expired', NULL, FlashMessage::ERROR);
             }
         } else {
             $this->addLocalizedFlashMessage('resetPassword.failed.invalid', NULL, FlashMessage::ERROR);
         }
     } else {
         $this->addLocalizedFlashMessage('resetPassword.failed.expired', NULL, FlashMessage::ERROR);
     }
     $loginPageUid = $this->getSettingValue('login.page');
     $this->redirect('showLoginForm', NULL, NULL, NULL, $loginPageUid);
 }
 /**
  * Clear the class cache
  *
  * @return void
  */
 public function clear()
 {
     $this->cacheInstance->flush();
     if (isset($GLOBALS['BE_USER'])) {
         $GLOBALS['BE_USER']->writelog(3, 1, 0, 0, '[StaticInfoTables]: User %s has cleared the class cache', array($GLOBALS['BE_USER']->user['username']));
     }
 }
 /**
  * Register the given brush for deferred loading.
  *
  * @param AbstractBrush $brush
  *
  * @return void
  */
 public function handle(AbstractBrush $brush)
 {
     $brushes = [];
     $aliases = [];
     if ($this->cache->has('brushes')) {
         $brushes = (array) $this->cache->get('brushes');
     }
     if (isset($brushes[$brush->identifier])) {
         $aliases = (array) $brushes[$brush->identifier];
     }
     $aliasKeys = array_flip($aliases);
     if (!isset($aliasKeys[$brush->alias])) {
         array_push($aliases, $brush->alias);
     }
     $brushes[$brush->identifier] = $aliases;
     $this->cache->set('brushes', $brushes);
 }
 /**
  * @param array             $params
  * @param FrontendInterface $frontend
  */
 public function set($params, $frontend)
 {
     /* We're only intrested in the page cache */
     if ($frontend->getIdentifier() !== 'cache_pages') {
         return;
     }
     $data = $params['variable'];
     $tags = $params['tags'];
     $lifetime = $params['lifetime'];
     $uri = GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL');
     $temp_content = isset($data['temp_content']) && $data['temp_content'];
     $tsfe = $this->getTypoScriptFrontendController();
     $cachable = $temp_content === false && $tsfe->isStaticCacheble() && $tsfe->doWorkspacePreview() === false && strpos($uri, '?') === false && in_array('nginx_cache_ignore', $tags) === false;
     if ($cachable) {
         $this->getCacheManager()->getCache('nginx_cache')->set(md5($uri), $uri, $tags, $lifetime);
     }
 }
 public function jsFooterInlineAction()
 {
     if (!$this->cache->has('brushes')) {
         return '';
     }
     // arguments for the AddPageAssetListenerInterface implementation
     $this->request->setArgument('compress', false);
     $this->request->setArgument('forceOnTop', false);
     $this->view->assign('brushes', $this->cache->get('brushes'));
 }
 public function geoJSONAction()
 {
     $geoJson = '{}';
     if (is_numeric($uid = GeneralUtility::_GP('uid'))) {
         // Don't return anything, not even cached entry, if the map is not in the repository
         if (!is_null($map = $this->mapRepository->findByIdentifier($uid))) {
             if ($GLOBALS['TSFE']->sys_page->versioningPreview) {
                 $geoJson = $this->geoJSONService->generateFeatureCollectionGeoJSON($map->getFeatures());
             } else {
                 if ($this->frontend->get($uid) == FALSE) {
                     $geoJson = $this->geoJSONService->generateFeatureCollectionGeoJSON($map->getFeatures());
                     $this->frontend->set($uid, $geoJson);
                 } else {
                     $geoJson = $this->frontend->get($uid);
                 }
             }
         }
     }
     return $geoJson;
 }
Example #10
0
 /**
  * cache resource
  *
  * @param $resource
  * @return void
  */
 protected function cacheResource($resource)
 {
     if (!empty($resource)) {
         $cacheKey = $this->getCacheIdentifierForPath($resource['path']);
         if (!$this->cache->has($cacheKey)) {
             if (!$resource['is_dir']) {
                 $this->cache->set($cacheKey, $resource);
             }
         }
     }
 }
 /**
  * Checks if a cache entry is given for given versions and filter text and tries to load the data array from cache.
  *
  * @param array $versions All records uids etc. First key is table name, second key incremental integer. Records are associative arrays with uid and t3ver_oid fields. The pid of the online record is found as "livepid" the pid of the offline record is found in "wspid
  * @param string $filterTxt The given filter text from the grid.
  * @return boolean TRUE if cache entry was successfully fetched from cache and content put to $this->dataArray
  */
 protected function getDataArrayFromCache(array $versions, $filterTxt)
 {
     $cacheEntry = FALSE;
     $hash = $this->calculateHash($versions, $filterTxt);
     $content = $this->workspacesCache->get($hash);
     if ($content !== FALSE) {
         $this->dataArray = $content;
         $cacheEntry = TRUE;
     }
     return $cacheEntry;
 }
Example #12
0
 /**
  * Flush data from cache table
  *
  * @return void
  */
 public function flushCacheTable()
 {
     $this->cacheFrontend->flush();
 }
 /**
  * @param string $identifier
  * @param string $content
  * @return void
  */
 protected function setToCache($identifier, $content)
 {
     $this->cache->set($identifier, $content);
 }
 public function setCached($url, $content)
 {
     $this->cache->set($this->calculateCacheIdentifier($url), $content, array(), $this->seconds);
     return $this->isCached($url);
 }
Example #15
0
 /**
  * @return void
  */
 public function flush()
 {
     self::$firstLevelCache[$this->cacheName] = array();
     $this->secondLevelCache->flush();
 }
Example #16
0
	/**
	 * Sets a reference to the cache frontend which uses this backend
	 *
	 * @param \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache The frontend for this backend
	 * @return void
	 * @api
	 */
	public function setCache(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache) {
		$this->cache = $cache;
		$this->cacheIdentifier = $this->cache->getIdentifier();
	}
Example #17
0
 /**
  * Registers a cache so it can be retrieved at a later point.
  *
  * @param \TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache The cache frontend to be registered
  * @return void
  * @throws \TYPO3\CMS\Core\Cache\Exception\DuplicateIdentifierException if a cache with the given identifier has already been registered.
  * @api
  */
 public function registerCache(\TYPO3\CMS\Core\Cache\Frontend\FrontendInterface $cache)
 {
     $identifier = $cache->getIdentifier();
     if (isset($this->caches[$identifier])) {
         throw new \TYPO3\CMS\Core\Cache\Exception\DuplicateIdentifierException('A cache with identifier "' . $identifier . '" has already been registered.', 1203698223);
     }
     $this->caches[$identifier] = $cache;
 }
Example #18
0
 public function flush()
 {
     $this->cacheInstance->flush();
 }
Example #19
0
 /**
  * Returns a cache entry
  *
  * @param string $entryIdentifier Cache entry identifier
  *
  * @return mixed
  */
 public function get($entryIdentifier)
 {
     return $this->cache->get($entryIdentifier);
 }
 /**
  * Writes to cache.
  *
  * @param string                $cacheIdentifier
  * @param ErrorHandlerInterface $errorHandler
  */
 public function set($cacheIdentifier, ErrorHandlerInterface $errorHandler)
 {
     $tags = (array) $errorHandler->getCacheTags();
     $data = json_encode(array('class' => get_class($errorHandler), 'data' => $errorHandler->getCachingData()));
     $this->cacheInstance->set($cacheIdentifier, $data, $tags);
 }
 /**
  *
  */
 public function flush()
 {
     $this->cache->flush();
 }