getCachedSegment() public method

Tries to retrieve the specified content segment from the cache – further nested inline segments are retrieved as well and segments which were not cacheable are rendered.
public getCachedSegment ( Closure $uncachedCommandCallback, string $typoScriptPath, array $cacheIdentifierValues, boolean $addCacheSegmentMarkersToPlaceholders = false ) : string | boolean
$uncachedCommandCallback Closure A callback to process commands in uncached segments
$typoScriptPath string TypoScript path identifying the TypoScript object to retrieve from the content cache
$cacheIdentifierValues array Further values which play into the cache identifier hash, must be the same as the ones specified while the cache entry was written
$addCacheSegmentMarkersToPlaceholders boolean If cache segment markers should be added – this makes sense if the cached segment is about to be included in a not-yet-cached segment
return string | boolean The segment with replaced cache placeholders, or FALSE if a segment was missing in the cache
 /**
  * Check for cached evaluation and or collect metadata for evaluation
  *
  * Try to get a cached segment for the current path and return that with all uncached segments evaluated if it
  * exists. Otherwise metadata for the cache lifetime is collected (if configured) for nested evaluations (to find the
  * minimum maximumLifetime).
  *
  * @param array $evaluateContext The current evaluation context
  * @param object $tsObject The current TypoScript object (for "this" in evaluations)
  * @return array Cache hit state as boolean and value as mixed
  */
 public function preEvaluate(array &$evaluateContext, $tsObject)
 {
     if ($this->enableContentCache) {
         if ($evaluateContext['cacheForPathEnabled']) {
             $evaluateContext['cacheIdentifierValues'] = $this->buildCacheIdentifierValues($evaluateContext['configuration'], $evaluateContext['typoScriptPath'], $tsObject);
             $self = $this;
             $segment = $this->contentCache->getCachedSegment(function ($command, $additionalData, $cache) use($self, $evaluateContext, $tsObject) {
                 if (strpos($command, 'eval=') === 0) {
                     $unserializedContext = $self->unserializeContext($additionalData['context']);
                     $path = substr($command, 5);
                     $result = $self->evaluateUncached($path, $unserializedContext);
                     return $result;
                 } elseif (strpos($command, 'evalCached=') === 0) {
                     $identifier = substr($command, 11);
                     $cacheDiscriminator = $this->runtime->evaluate($additionalData['path'] . '/__meta/cache/entryDiscriminator');
                     $cacheIdentifier = substr($identifier, 0, strpos($identifier, '_')) . '_' . md5($cacheDiscriminator);
                     $result = $cache->get($cacheIdentifier);
                     if ($result === false) {
                         $unserializedContext = $self->unserializeContext($additionalData['context']);
                         $maximumLifetime = null;
                         if (isset($evaluateContext['configuration']['maximumLifetime'])) {
                             $maximumLifetime = $this->runtime->evaluate($evaluateContext['typoScriptPath'] . '/__meta/cache/maximumLifetime', $tsObject);
                         }
                         $cacheTags = $this->buildCacheTags($evaluateContext['configuration'], $evaluateContext['typoScriptPath'], $tsObject);
                         $result = $self->evaluateUncached($additionalData['path'], $unserializedContext);
                         $cache->set($cacheIdentifier, $result, $cacheTags, $maximumLifetime);
                     }
                     return $result;
                 } else {
                     throw new Exception(sprintf('Unknown uncached command "%s"', $command), 1392837596);
                 }
             }, $evaluateContext['typoScriptPath'], $evaluateContext['cacheIdentifierValues'], $this->addCacheSegmentMarkersToPlaceholders);
             if ($segment !== false) {
                 return [true, $segment];
             } else {
                 $this->addCacheSegmentMarkersToPlaceholders = true;
             }
             $this->cacheMetadata[] = ['lifetime' => null];
         }
         if ($evaluateContext['cacheForPathEnabled'] && $evaluateContext['cacheForPathDisabled']) {
             $evaluateContext['cacheDiscriminator'] = $this->runtime->evaluate($evaluateContext['typoScriptPath'] . '/__meta/cache/entryDiscriminator');
         }
         if (isset($evaluateContext['configuration']['maximumLifetime'])) {
             $maximumLifetime = $this->runtime->evaluate($evaluateContext['typoScriptPath'] . '/__meta/cache/maximumLifetime', $tsObject);
             if ($maximumLifetime !== null && $this->cacheMetadata !== []) {
                 $cacheMetadata =& $this->cacheMetadata[count($this->cacheMetadata) - 1];
                 $cacheMetadata['lifetime'] = $cacheMetadata['lifetime'] !== null ? min($cacheMetadata['lifetime'], $maximumLifetime) : $maximumLifetime;
             }
         }
     }
     return [false, null];
 }