Drupal 8  8.0.2
CacheableMetadata Class Reference
Inheritance diagram for CacheableMetadata:

Public Member Functions

 getCacheTags ()
 
 setCacheTags (array $cache_tags)
 
 getCacheContexts ()
 
 setCacheContexts (array $cache_contexts)
 
 getCacheMaxAge ()
 
 setCacheMaxAge ($max_age)
 
 merge (CacheableMetadata $other)
 
 applyTo (array &$build)
 
- Public Member Functions inherited from RefinableCacheableDependencyInterface
 addCacheContexts (array $cache_contexts)
 
 addCacheTags (array $cache_tags)
 
 mergeCacheMaxAge ($max_age)
 
 addCacheableDependency ($other_object)
 

Static Public Member Functions

static createFromRenderArray (array $build)
 
static createFromObject ($object)
 

Detailed Description

Defines a generic class for passing cacheability metadata.

Member Function Documentation

applyTo ( array &  $build)

Applies the values of this CacheableMetadata object to a render array.

Parameters
array&$buildA render array.
static createFromObject (   $object)
static

Creates a CacheableMetadata object from a depended object.

Parameters
\Drupal\Core\Cache\CacheableDependencyInterface | mixed$objectThe object whose cacheability metadata to retrieve. If it implements CacheableDependencyInterface, its cacheability metadata will be used, otherwise, the passed in object must be assumed to be uncacheable, so max-age 0 is set.
Returns
static

Referenced by Context\addCacheableDependency(), Renderer\addCacheableDependency(), TestDisplayVariant\build(), EntityReferenceFormatterBase\getEntitiesToView(), SystemController\overview(), MenuParentFormSelector\parentSelectOptionsTreeWalk(), DynamicPageCacheSubscriber\responseToRenderArray(), and CacheableMetadataTest\testCreateFromObject().

Here is the caller graph for this function:

static createFromRenderArray ( array  $build)
static

Creates a CacheableMetadata object with values taken from a render array.

Parameters
array$buildA render array.
Returns
static

References Cache\PERMANENT.

Referenced by Renderer\addCacheableDependency(), RenderCache\createCacheID(), Renderer\doRender(), BlockViewBuilder\preRender(), JsonRenderer\renderResponse(), DynamicPageCacheSubscriber\responseToRenderArray(), RenderCache\set(), HtmlResponse\setContent(), CacheableMetadataTest\testCreateFromRenderArray(), and EntityReferenceFormatterBase\view().

Here is the caller graph for this function:

getCacheContexts ( )

{The cache contexts associated with this object.These identify a specific variation/representation of the object.Cache contexts are tokens: placeholders that are converted to cache keys by the service. The replacement value depends on the request context (the current URL, language, and so on). They're converted before storing an object in cache.

Returns
string[] An array of cache context tokens, used to generate a cache ID.
See Also
::convertTokensToKeys()
}

Implements CacheableDependencyInterface.

Referenced by TokenTest\testReplaceWithHookTokensAlterWithBubbleableMetadata().

Here is the caller graph for this function:

getCacheMaxAge ( )

{The maximum age for which this object may be cached.

Returns
int The maximum time in seconds that this object may be cached.
}

Implements CacheableDependencyInterface.

Referenced by TokenTest\testReplaceWithHookTokensAlterWithBubbleableMetadata().

Here is the caller graph for this function:

getCacheTags ( )

{The cache tags associated with this object.When this object is modified, these cache tags will be invalidated.

Returns
string[] A set of cache tags.
}

Implements CacheableDependencyInterface.

Referenced by TokenTest\testReplaceWithHookTokensAlterWithBubbleableMetadata().

Here is the caller graph for this function:

merge ( CacheableMetadata  $other)

Merges the values of another CacheableMetadata object with this one.

Parameters
\Drupal\Core\Cache\CacheableMetadata$otherThe other CacheableMetadata object.
Returns
static A new CacheableMetadata object, with the merged data.

References Cache\mergeContexts(), Cache\mergeMaxAges(), Cache\mergeTags(), and Cache\PERMANENT.

Referenced by CacheableMetadataTest\testMerge().

Here is the call graph for this function:

Here is the caller graph for this function:

setCacheContexts ( array  $cache_contexts)

Sets cache contexts.

Parameters
string[]$cache_contexts The cache contexts to be associated.
Returns
$this

Referenced by TokenTest\testReplaceWithHookTokensAlterWithBubbleableMetadata().

Here is the caller graph for this function:

setCacheMaxAge (   $max_age)

Sets the maximum age (in seconds).

Defaults to Cache::PERMANENT

Parameters
int$max_ageThe max age to associate.
Returns
$this
Exceptions
\InvalidArgumentExceptionIf a non-integer value is supplied.

Referenced by TokenTest\testReplaceWithHookTokensAlterWithBubbleableMetadata().

Here is the caller graph for this function:

setCacheTags ( array  $cache_tags)

Sets cache tags.

Parameters
string[]$cache_tags The cache tags to be associated.
Returns
$this

The documentation for this class was generated from the following file: