set() public method

Saves the value of a PHP variable in the cache.
public set ( string $entryIdentifier, string $string, array $tags = [], integer $lifetime = null ) : void
$entryIdentifier string An identifier used for this cache entry
$string string The variable to cache
$tags array Tags to associate with this cache entry
$lifetime integer Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
return void
 /**
  * Redirects to the Neos backend on the given site, passing a one-time login token
  *
  * @param Site $site
  * @return void
  */
 public function switchSiteAction($site)
 {
     $token = Algorithms::generateRandomToken(32);
     $this->loginTokenCache->set($token, $this->currentSession->getId());
     $siteUri = $this->linkingService->createSiteUri($this->controllerContext, $site);
     $loginUri = $this->controllerContext->getUriBuilder()->reset()->uriFor('tokenLogin', ['token' => $token], 'Login', 'Neos.Neos');
     $this->redirectToUri($siteUri . $loginUri);
 }
 /**
  * @return string The current cache version identifier
  */
 public function render()
 {
     $version = $this->configurationCache->get('ConfigurationVersion');
     if ($version === false) {
         $version = time();
         $this->configurationCache->set('ConfigurationVersion', (string) $version);
     }
     return $version;
 }
 /**
  * Stores the $uriPath in the cache together with the $routeValues
  *
  * @param string $uriPath
  * @param array $routeValues
  * @return void
  */
 public function storeResolvedUriPath($uriPath, array $routeValues)
 {
     $uriPath = trim($uriPath, '/');
     $routeValues = $this->convertObjectsToHashes($routeValues);
     if ($routeValues === null) {
         return;
     }
     $cacheIdentifier = $this->buildResolveCacheIdentifier($routeValues);
     if ($cacheIdentifier !== null) {
         $tags = $this->generateRouteTags($uriPath, $routeValues);
         $this->resolveCache->set($cacheIdentifier, $uriPath, $tags);
     }
 }
 /**
  * Returns the encryption key from the persistent cache or Data/Persistent directory. If none exists, a new
  * encryption key will be generated and stored in the cache.
  *
  * @return string The configured encryption key stored in Data/Persistent/EncryptionKey
  */
 protected function getEncryptionKey()
 {
     if ($this->encryptionKey === null) {
         $this->encryptionKey = $this->cache->get('encryptionKey');
     }
     if ($this->encryptionKey === false && file_exists(FLOW_PATH_DATA . 'Persistent/EncryptionKey')) {
         $this->encryptionKey = file_get_contents(FLOW_PATH_DATA . 'Persistent/EncryptionKey');
     }
     if ($this->encryptionKey === false) {
         $this->encryptionKey = bin2hex(Utility\Algorithms::generateRandomBytes(48));
         $this->cache->set('encryptionKey', $this->encryptionKey);
     }
     return $this->encryptionKey;
 }
 /**
  * Takes a string of content which includes cache segment markers, extracts the marked segments, writes those
  * segments which can be cached to the actual cache and returns the cleaned up original content without markers.
  *
  * This method is called by the TypoScript Runtime while rendering a TypoScript object.
  *
  * @param string $content The content with an outer cache segment
  * @param boolean $storeCacheEntries Whether to store extracted cache segments in the cache
  * @return string The (pure) content without cache segment markers
  */
 public function processCacheSegments($content, $storeCacheEntries = true)
 {
     $this->parser->extractRenderedSegments($content, $this->randomCacheMarker);
     if ($storeCacheEntries) {
         $segments = $this->parser->getCacheSegments();
         foreach ($segments as $segment) {
             $metadata = explode(';', $segment['metadata']);
             $tagsValue = $metadata[0] === '' ? [] : ($metadata[0] === '*' ? false : explode(',', $metadata[0]));
             // FALSE means we do not need to store the cache entry again (because it was previously fetched)
             if ($tagsValue !== false) {
                 $lifetime = isset($metadata[1]) ? (int) $metadata[1] : null;
                 $this->cache->set($segment['identifier'], $segment['content'], $this->sanitizeTags($tagsValue), $lifetime);
             }
         }
     }
     return $this->parser->getOutput();
 }
 /**
  * Loads all node types into memory.
  *
  * @return void
  */
 protected function loadNodeTypes()
 {
     $this->fullNodeTypeConfigurations = $this->fullConfigurationCache->get('fullNodeTypeConfigurations');
     $fillFullConfigurationCache = !is_array($this->fullNodeTypeConfigurations);
     $completeNodeTypeConfiguration = $this->configurationManager->getConfiguration('NodeTypes');
     foreach (array_keys($completeNodeTypeConfiguration) as $nodeTypeName) {
         if (!is_array($completeNodeTypeConfiguration[$nodeTypeName])) {
             continue;
         }
         $nodeType = $this->loadNodeType($nodeTypeName, $completeNodeTypeConfiguration, isset($this->fullNodeTypeConfigurations[$nodeTypeName]) ? $this->fullNodeTypeConfigurations[$nodeTypeName] : null);
         if ($fillFullConfigurationCache) {
             $this->fullNodeTypeConfigurations[$nodeTypeName] = $nodeType->getFullConfiguration();
         }
     }
     if ($fillFullConfigurationCache) {
         $this->fullConfigurationCache->set('fullNodeTypeConfigurations', $this->fullNodeTypeConfigurations);
     }
     $this->fullNodeTypeConfigurations = null;
 }
 /**
  * Store the changed directories and files back to the cache.
  *
  * @return void
  */
 protected function saveDetectedDirectoriesAndFiles()
 {
     $this->cache->set($this->identifier . '_directoriesAndFiles', json_encode($this->directoriesAndFiles));
 }
 /**
  * Caches the file modification times
  *
  * @return void
  */
 public function shutdownObject()
 {
     if ($this->modificationTimesChanged === true) {
         $this->cache->set($this->fileMonitor->getIdentifier() . '_filesAndModificationTimes', json_encode($this->filesAndModificationTimes));
     }
 }
Ejemplo n.º 9
0
 /**
  * Set updated reflection data to caches.
  */
 protected function updateReflectionData()
 {
     $this->log(sprintf('Found %s classes whose reflection data was not cached previously.', count($this->updatedReflectionData)), LOG_DEBUG);
     foreach (array_keys($this->updatedReflectionData) as $className) {
         $this->statusCache->set($this->produceCacheIdentifierFromClassName($className), '');
     }
     $data = [];
     $propertyNames = ['classReflectionData', 'classSchemata', 'annotatedClasses', 'classesByMethodAnnotations'];
     foreach ($propertyNames as $propertyName) {
         $data[$propertyName] = $this->{$propertyName};
     }
     $this->reflectionDataCompiletimeCache->set('ReflectionData', $data);
 }
 /**
  * @test
  * @expectedException \Neos\Cache\Exception\InvalidDataException
  */
 public function setThrowsInvalidDataExceptionOnNonStringValues()
 {
     $backend = $this->prepareDefaultBackend();
     $cache = new StringFrontend('StringFrontend', $backend);
     $cache->set('StringCacheTest', []);
 }