ContentCache
class ContentCache (View source)
A wrapper around a Neos Flow cache which provides additional functionality for caching partial content (segments) rendered by the Fusion Runtime.
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.
Constants
CACHE_SEGMENT_START_TOKEN |
|
CACHE_SEGMENT_END_TOKEN |
|
CACHE_SEGMENT_SEPARATOR_TOKEN |
|
CACHE_SEGMENT_MARKER |
|
CACHE_PLACEHOLDER_REGEX |
|
EVAL_PLACEHOLDER_REGEX |
|
MAXIMUM_NESTING_LEVEL |
|
TAG_EVERYTHING |
A cache entry tag that will be used by default to flush an entry on "every" change - whatever that means to
the application. |
SEGMENT_TYPE_CACHED |
|
SEGMENT_TYPE_UNCACHED |
|
SEGMENT_TYPE_DYNAMICCACHED |
|
Properties
protected StringFrontend | $cache | ||
protected PropertyMapper | $propertyMapper | ||
protected Context | $securityContext | ||
protected string | $randomCacheMarker |
Methods
ContentCache constructor
Takes the given content and adds markers for later use as a cached content segment.
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.
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.
Renders an identifier for a content cache entry
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.
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.
Find cache placeholders in a cached segment and return the identifiers
Replace segments which are marked as not-cacheable by their actual content by invoking the Fusion Runtime.
Generates an array of strings from the given array of context variables
TODO: Adapt to Flow change https://review.typo3.org/#/c/33138/
Flush content cache entries by tag
Flush content cache entries by tags
Flush all content cache entries
Sanitizes the given tag for use with the cache framework
Sanitizes multiple tags with sanitizeTag()
Details
__construct()
ContentCache constructor
string
createCacheSegment(string $content, string $fusionPath, array $cacheIdentifierValues, array $tags = [], int $lifetime = null)
Takes the given content and adds markers for later use as a cached content segment.
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 Fusion path and additional values which were defined in the Fusion 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 Fusion Runtime while rendering a Fusion object.
string
createUncachedSegment(string $content, string $fusionPath, array $contextVariables)
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.
This method is called by the Fusion Runtime while rendering a Fusion object.
string
createDynamicCachedSegment(string $content, string $fusionPath, array $contextVariables, array $cacheIdentifierValues, array $tags, int $lifetime, string $cacheDiscriminator)
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.
This method is called by the Fusion Runtime while rendering a Fusion object.
protected string
renderContentCacheEntryIdentifier(string $fusionPath, array $cacheIdentifierValues)
Renders an identifier for a content cache entry
string
processCacheSegments(string $content, bool $storeCacheEntries = true)
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 Fusion Runtime while rendering a Fusion object.
string|false
getCachedSegment(Closure $uncachedCommandCallback, string $fusionPath, array $cacheIdentifierValues, bool $addCacheSegmentMarkersToPlaceholders = false, string|false $cacheDiscriminator = null)
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.
protected int|bool
replaceCachePlaceholders(string $content, bool $addCacheSegmentMarkersToPlaceholders)
Find cache placeholders in a cached segment and return the identifiers
protected int
replaceUncachedPlaceholders(Closure $uncachedCommandCallback, string $content)
Replace segments which are marked as not-cacheable by their actual content by invoking the Fusion Runtime.
protected array
serializeContext(array $contextVariables)
Generates an array of strings from the given array of context variables
protected string
getTypeForContextValue(mixed $contextValue)
TODO: Adapt to Flow change https://review.typo3.org/#/c/33138/
int
flushByTag(string $tag)
Flush content cache entries by tag
int
flushByTags(array $tags)
Flush content cache entries by tags
void
flush()
Flush all content cache entries
protected string
sanitizeTag(string $tag)
Sanitizes the given tag for use with the cache framework
protected array
sanitizeTags(array $tags)
Sanitizes multiple tags with sanitizeTag()