PHP Class Neos\Fusion\Core\Cache\ContentCache

The cache build process generally follows these steps: - render the whole document as usual (for example a page) but insert special markers before and after the rendered segments - parse the rendered document and extract segments by the previously added markers This results in two artifacts: - an array of content segments which are later stored as cache entries (if they may be cached) - a string called "output" which is the originally rendered output but without the markers We use non-visible ASCII characters as markers / tokens in order to minimize potential conflicts with the actual content. Note: If you choose a different cache backend for this content cache, make sure that it is one implementing TaggableBackendInterface.
Show file Open project: neos/neos-development-collection Class Usage Examples

Protected Properties

Property Type Description
$cache Neos\Cache\Frontend\StringFrontend
$parser CacheSegmentParser
$propertyMapper Neos\Flow\Property\PropertyMapper
$randomCacheMarker string
$securityContext Neos\Flow\Security\Context

Public Methods

Method Description
__construct ( ) ContentCache constructor
createCacheSegment ( string $content, string $typoScriptPath, array $cacheIdentifierValues, array $tags = [], integer $lifetime = null ) : string Takes the given content and adds markers for later use as a cached content segment.
createDynamicCachedSegment ( string $content, string $typoScriptPath, array $contextVariables, array $cacheIdentifierValues, array $tags = [], integer $lifetime = null, string $cacheDiscriminator ) : string Similar to createUncachedSegment() creates a content segment with markers added, but in contrast to that function this method is used for rendering a segment which will be evaluated at runtime but can still be cached.
createUncachedSegment ( string $content, string $typoScriptPath, array $contextVariables ) : string Similar to createCacheSegment() creates a content segment with markers added, but in contrast to that function this method is used for rendering a segment which is not supposed to be cached.
flush ( ) : void Flush all content cache entries
flushByTag ( string $tag ) : integer Flush content cache entries by tag
getCachedSegment ( Closure $uncachedCommandCallback, string $typoScriptPath, array $cacheIdentifierValues, boolean $addCacheSegmentMarkersToPlaceholders = false ) : string | boolean 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.
processCacheSegments ( string $content, boolean $storeCacheEntries = true ) : string 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.

Protected Methods

Method Description
getTypeForContextValue ( mixed $contextValue ) : string TODO: Adapt to Flow change https://review.typo3.org/#/c/33138/
renderContentCacheEntryIdentifier ( string $typoScriptPath, array $cacheIdentifierValues ) : string Renders an identifier for a content cache entry
replaceCachePlaceholders ( string &$content, boolean $addCacheSegmentMarkersToPlaceholders ) : integer | boolean Find cache placeholders in a cached segment and return the identifiers
replaceUncachedPlaceholders ( Closure $uncachedCommandCallback, string &$content ) : string Replace segments which are marked as not-cacheable by their actual content by invoking the TypoScript Runtime.
sanitizeTag ( string $tag ) : string Sanitizes the given tag for use with the cache framework
sanitizeTags ( array $tags ) : array Sanitizes multiple tags with sanitizeTag()
serializeContext ( array $contextVariables ) : array Generates an array of strings from the given array of context variables

Method Details

__construct() public method

ContentCache constructor
public __construct ( )

createCacheSegment() public method

This function will add a start and an end token to the beginning and end of the content and generate a cache identifier based on the current TypoScript path and additional values which were defined in the TypoScript configuration by the site integrator. The whole cache segment (START TOKEN + IDENTIFIER + SEPARATOR TOKEN + original content + END TOKEN) is returned as a string. This method is called by the TypoScript Runtime while rendering a TypoScript object.
public createCacheSegment ( string $content, string $typoScriptPath, array $cacheIdentifierValues, array $tags = [], integer $lifetime = null ) : string
$content string The (partial) content which should potentially be cached later on
$typoScriptPath string The TypoScript path that rendered the content, for example "page/body/parts/breadcrumbMenu"
$cacheIdentifierValues array The values (simple type or implementing CacheAwareInterface) that should be used to create a cache identifier, will be sorted by keys for consistent ordering
$tags array Tags to add to the cache entry
$lifetime integer Lifetime of the cache segment in seconds. NULL for the default lifetime and 0 for unlimited lifetime.
return string The original content, but with additional markers and a cache identifier added

createDynamicCachedSegment() public method

This method is called by the TypoScript Runtime while rendering a TypoScript object.
public createDynamicCachedSegment ( string $content, string $typoScriptPath, array $contextVariables, array $cacheIdentifierValues, array $tags = [], integer $lifetime = null, string $cacheDiscriminator ) : string
$content string The content rendered by the TypoScript Runtime
$typoScriptPath string The TypoScript path that rendered the content, for example "page/body/parts/breadcrumbMenu"
$contextVariables array TypoScript context variables which are needed to correctly render the specified TypoScript object
$cacheIdentifierValues array
$tags array Tags to add to the cache entry
$lifetime integer Lifetime of the cache segment in seconds. NULL for the default lifetime and 0 for unlimited lifetime.
$cacheDiscriminator string The evaluated cache discriminator value
return string The original content, but with additional markers added

createUncachedSegment() public method

This method is called by the TypoScript Runtime while rendering a TypoScript object.
public createUncachedSegment ( string $content, string $typoScriptPath, array $contextVariables ) : string
$content string The content rendered by the TypoScript Runtime
$typoScriptPath string The TypoScript path that rendered the content, for example "page/body/parts/breadcrumbMenu"
$contextVariables array TypoScript context variables which are needed to correctly render the specified TypoScript object
return string The original content, but with additional markers added

flush() public method

Flush all content cache entries
public flush ( ) : void
return void

flushByTag() public method

Flush content cache entries by tag
public flushByTag ( string $tag ) : integer
$tag string A tag value that was assigned to a cache entry in TypoScript, for example "Everything", "Node_[…]", "NodeType_[…]", "DescendantOf_[…]" whereas "…" is the node identifier or node type respectively
return integer The number of cache entries which actually have been flushed

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

getTypeForContextValue() protected method

TODO: Adapt to Flow change https://review.typo3.org/#/c/33138/
protected getTypeForContextValue ( mixed $contextValue ) : string
$contextValue mixed
return string

processCacheSegments() public method

This method is called by the TypoScript Runtime while rendering a TypoScript object.
public processCacheSegments ( string $content, boolean $storeCacheEntries = true ) : string
$content string The content with an outer cache segment
$storeCacheEntries boolean Whether to store extracted cache segments in the cache
return string The (pure) content without cache segment markers

renderContentCacheEntryIdentifier() protected method

Renders an identifier for a content cache entry
protected renderContentCacheEntryIdentifier ( string $typoScriptPath, array $cacheIdentifierValues ) : string
$typoScriptPath string
$cacheIdentifierValues array
return string An MD5 hash built from the typoScriptPath and certain elements of the given identifier values

replaceCachePlaceholders() protected method

Find cache placeholders in a cached segment and return the identifiers
protected replaceCachePlaceholders ( string &$content, boolean $addCacheSegmentMarkersToPlaceholders ) : integer | boolean
$content string
$addCacheSegmentMarkersToPlaceholders boolean
return integer | boolean Number of replaced placeholders or FALSE if a placeholder couldn't be found

replaceUncachedPlaceholders() protected method

Replace segments which are marked as not-cacheable by their actual content by invoking the TypoScript Runtime.
protected replaceUncachedPlaceholders ( Closure $uncachedCommandCallback, string &$content ) : string
$uncachedCommandCallback Closure
$content string The content potentially containing not cacheable segments marked by the respective tokens
return string The original content, but with uncached segments replaced by the actual content

sanitizeTag() protected method

Sanitizes the given tag for use with the cache framework
protected sanitizeTag ( string $tag ) : string
$tag string A tag which possibly contains non-allowed characters, for example "NodeType_Neos.NodeTypes:Page"
return string A cleaned up tag, for example "NodeType_TYPO3_Neos-Page"

sanitizeTags() protected method

Sanitizes multiple tags with sanitizeTag()
protected sanitizeTags ( array $tags ) : array
$tags array Multiple tags
return array The sanitized tags

serializeContext() protected method

Generates an array of strings from the given array of context variables
protected serializeContext ( array $contextVariables ) : array
$contextVariables array
return array

Property Details

$cache protected property

protected StringFrontend,Neos\Cache\Frontend $cache
return Neos\Cache\Frontend\StringFrontend

$parser protected property

protected CacheSegmentParser,Neos\Fusion\Core\Cache $parser
return CacheSegmentParser

$propertyMapper protected property

protected PropertyMapper,Neos\Flow\Property $propertyMapper
return Neos\Flow\Property\PropertyMapper

$randomCacheMarker protected property

protected string $randomCacheMarker
return string

$securityContext protected property

protected Context,Neos\Flow\Security $securityContext
return Neos\Flow\Security\Context