class PlaceholderingRenderCache

Adds automatic placeholdering to the RenderCache.

This automatic placeholdering is performed to ensure the containing elements and overarching response are as cacheable as possible. Elements whose subtree bubble either max-age=0 or high-cardinality cache contexts (such as 'user' and 'session') are considered poorly cacheable.

Automatic placeholdering is performed only on elements whose subtree was generated using a #lazy_builder callback and whose bubbled cacheability meets the auto-placeholdering conditions as configured in the renderer.config container parameter.

This RenderCache implementation automatically replaces an element with a placeholder:

  • on render cache hit, i.e. ::get()
  • on render cache miss, i.e. ::set() (in subsequent requests, it will be a cache hit)

In either case, the render cache is guaranteed to contain the to-be-rendered placeholder, so replacing (rendering) the placeholder will be very fast.

Finally, in case the render cache item disappears between the time it is decided to automatically placeholder the element and the time where the placeholder is replaced (rendered), that is guaranteed to not be problematic. Because this only automatically placeholders elements that have a #lazy_builder callback set, which means that in the worst case, it will need to be re-rendered.

Hierarchy

See also

sites/default/default.services.yml

File

core/lib/Drupal/Core/Render/PlaceholderingRenderCache.php, line 40

Namespace

Drupal\Core\Render

Members

Name Modifiers Type Description
PlaceholderingRenderCache::$placeholderGenerator protected property The placeholder generator.
PlaceholderingRenderCache::$placeholderResultsCache protected property Stores rendered results for automatically placeholdered elements.
PlaceholderingRenderCache::createPlaceholderAndRemember protected function Create a placeholder for a renderable array and remember in a static cache.
PlaceholderingRenderCache::get public function Gets the cached, pre-rendered element of a renderable element from cache. Overrides RenderCache::get
PlaceholderingRenderCache::getFromPlaceholderResultsCache protected function Retrieves an auto-placeholdered renderable array from the static cache.
PlaceholderingRenderCache::set public function Caches the rendered output of a renderable array. Overrides RenderCache::set
PlaceholderingRenderCache::__construct public function Constructs a new PlaceholderingRenderCache object. Overrides RenderCache::__construct
RenderCache::$cacheContextsManager protected property The cache contexts manager.
RenderCache::$cacheFactory protected property The cache factory.
RenderCache::$requestStack protected property The request stack.
RenderCache::createCacheID protected function Creates the cache ID for a renderable element.
RenderCache::getCacheableRenderArray public function Gets a cacheable render array for a render array and its rendered output. Overrides RenderCacheInterface::getCacheableRenderArray
RenderCache::maxAgeToExpire protected function Maps a #cache[max-age] value to an "expire" value for the Cache API.

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Render!PlaceholderingRenderCache.php/class/PlaceholderingRenderCache/8.1.x