/** * @param string $identifier * @param \Callable $callback * @return mixed */ public function get($identifier, $callback) { if ($this->cache->has($identifier)) { return $this->cache->get($identifier); } $value = $callback(); $this->cache->set($identifier, $value); return $value; }
/** * Reads from cache. * * @param string $cacheIdentifier * @return ErrorHandlerInterface|null */ public function get($cacheIdentifier) { $cacheEntry = $this->cacheInstance->get($cacheIdentifier); if ($cacheEntry !== false) { $data = json_decode($cacheEntry, true); $errorHandler = $this->objectManager->get($data['class']); if ($errorHandler instanceof ErrorHandlerInterface) { $errorHandler->setCachingData($data['data']); return $errorHandler; } } return null; }
/** * 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); }
/** * Returns the actual rootline * * @return array */ public function get() { if (!isset(static::$localCache[$this->cacheIdentifier])) { $entry = static::$cache->get($this->cacheIdentifier); if (!$entry) { $this->generateRootlineCache(); } else { static::$localCache[$this->cacheIdentifier] = $entry; $depth = count($entry); // Populate the root-lines for parent pages as well // since they are part of the current root-line while ($depth > 1) { --$depth; $parentCacheIdentifier = $this->getCacheIdentifier($entry[$depth - 1]['uid']); // Abort if the root-line of the parent page is // already in the local cache data if (isset(static::$localCache[$parentCacheIdentifier])) { break; } // Behaves similar to array_shift(), but preserves // the array keys - which contain the page ids here $entry = array_slice($entry, 1, null, true); static::$localCache[$parentCacheIdentifier] = $entry; } } } return static::$localCache[$this->cacheIdentifier]; }
/** * 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; }
/** * get file or folder information from cache or directly from dropbox * * @param string $path Path to receive information from * @return array file or folder informations */ public function getMetaData($path) { $path = $path === '/' ? '/' : rtrim($path, '/'); if (trim($path, '/') === '_processed_') { return array('path' => '/_processed_', 'is_dir' => TRUE); } $cacheKey = $this->getCacheIdentifierForPath($path); try { if ($this->cache->has($cacheKey)) { $info = $this->cache->get($cacheKey); } else { $info = $this->dropboxClient->getMetadataWithChildren($path); $this->cache->set($cacheKey, $info); // create cache entries for sub resources if (!empty($info['contents'])) { foreach ($info['contents'] as $key => $resource) { if ($resource['path'] === '/_processed_') { unset($info['contents'][$key]); } else { $this->cacheResource($resource); } } } } } catch (\Exception $e) { // if something crashes return an empty array $info = array(); } return $info; }
/** * 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); }
/** * Retrieves a value from the first level cache if present and * from the second level if not. * * @param string $cacheId * @return mixed */ public function get($cacheId) { $firstLevelResult = $this->getFromFirstLevelCache($cacheId); if ($firstLevelResult !== null) { return $firstLevelResult; } return $this->secondLevelCache->get($cacheId); }
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')); }
/** * 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; }
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; }
/** * Returns the actual rootline * * @return array */ public function get() { $cacheIdentifier = $this->getCacheIdentifier(); if (!isset(self::$localCache[$cacheIdentifier])) { if (!self::$cache->has($cacheIdentifier)) { $this->generateRootlineCache(); } else { self::$localCache[$cacheIdentifier] = self::$cache->get($cacheIdentifier); } } return self::$localCache[$cacheIdentifier]; }
/** * Fetch value for hash from session * * @param string $key * * @return array */ public function getValueFromCacheTable($key) { return $this->cacheFrontend->get($key); }
/** * Returns a cache entry * * @param string $entryIdentifier Cache entry identifier * * @return mixed */ public function get($entryIdentifier) { return $this->cache->get($entryIdentifier); }
public function get($identifier) { return $this->cacheInstance->get($identifier); }
/** * @param string $identifier * @return string|NULL */ protected function getFromCache($identifier) { return $this->cache->get($identifier); }
public function getCached($url) { return $this->cache->get($this->calculateCacheIdentifier($url)); }