interface RefinableCacheableDependencyInterface

Same name in other branches
  1. 8.9.x core/lib/Drupal/Core/Cache/RefinableCacheableDependencyInterface.php \Drupal\Core\Cache\RefinableCacheableDependencyInterface
  2. 10 core/lib/Drupal/Core/Cache/RefinableCacheableDependencyInterface.php \Drupal\Core\Cache\RefinableCacheableDependencyInterface
  3. 11.x core/lib/Drupal/Core/Cache/RefinableCacheableDependencyInterface.php \Drupal\Core\Cache\RefinableCacheableDependencyInterface

Allows to add cacheability metadata to an object for the current runtime.

This must be used when changing an object in a way that affects its cacheability. For example, when changing the active translation of an entity based on the current content language then a cache context for that must be added.

Hierarchy

Expanded class hierarchy of RefinableCacheableDependencyInterface

All classes that implement RefinableCacheableDependencyInterface

22 files declare their use of RefinableCacheableDependencyInterface
AccessResult.php in core/lib/Drupal/Core/Access/AccessResult.php
Breadcrumb.php in core/lib/Drupal/Core/Breadcrumb/Breadcrumb.php
ComputedTestCacheableString.php in core/modules/system/tests/modules/entity_test/src/Plugin/DataType/ComputedTestCacheableString.php
ConfigBase.php in core/lib/Drupal/Core/Config/ConfigBase.php
CustomPageExceptionHtmlSubscriber.php in core/lib/Drupal/Core/EventSubscriber/CustomPageExceptionHtmlSubscriber.php

... See full list

File

core/lib/Drupal/Core/Cache/RefinableCacheableDependencyInterface.php, line 13

Namespace

Drupal\Core\Cache
View source
interface RefinableCacheableDependencyInterface extends CacheableDependencyInterface {
    
    /**
     * Adds cache contexts.
     *
     * @param string[] $cache_contexts
     *   The cache contexts to be added.
     *
     * @return $this
     */
    public function addCacheContexts(array $cache_contexts);
    
    /**
     * Adds cache tags.
     *
     * @param string[] $cache_tags
     *   The cache tags to be added.
     *
     * @return $this
     */
    public function addCacheTags(array $cache_tags);
    
    /**
     * Merges the maximum age (in seconds) with the existing maximum age.
     *
     * The max age will be set to the given value if it is lower than the existing
     * value.
     *
     * @param int $max_age
     *   The max age to associate.
     *
     * @return $this
     *
     * @throws \InvalidArgumentException
     *   Thrown if a non-integer value is supplied.
     */
    public function mergeCacheMaxAge($max_age);
    
    /**
     * Adds a dependency on an object: merges its cacheability metadata.
     *
     * @param \Drupal\Core\Cache\CacheableDependencyInterface|object $other_object
     *   The dependency. If the object implements CacheableDependencyInterface,
     *   then its cacheability metadata will be used. Otherwise, the passed in
     *   object must be assumed to be uncacheable, so max-age 0 is set.
     *
     * @return $this
     *
     * @see \Drupal\Core\Cache\CacheableMetadata::createFromObject()
     */
    public function addCacheableDependency($other_object);

}

Members

Title Sort descending Modifiers Object type Summary Overrides
CacheableDependencyInterface::getCacheContexts public function The cache contexts associated with this object. 34
CacheableDependencyInterface::getCacheMaxAge public function The maximum age for which this object may be cached. 34
CacheableDependencyInterface::getCacheTags public function The cache tags associated with this object. 27
RefinableCacheableDependencyInterface::addCacheableDependency public function Adds a dependency on an object: merges its cacheability metadata. 1
RefinableCacheableDependencyInterface::addCacheContexts public function Adds cache contexts. 1
RefinableCacheableDependencyInterface::addCacheTags public function Adds cache tags. 1
RefinableCacheableDependencyInterface::mergeCacheMaxAge public function Merges the maximum age (in seconds) with the existing maximum age. 1

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.