interface VariationCacheInterface
Defines an interface for variation cache implementations.
A variation cache wraps any provided cache backend and adds support for cache contexts to it. The actual caching still happens in the original cache backend.
Hierarchy
- interface \Drupal\Core\Cache\VariationCacheInterface
 
Expanded class hierarchy of VariationCacheInterface
All classes that implement VariationCacheInterface
Related topics
5 files declare their use of VariationCacheInterface
- AccessPolicyProcessor.php in core/
lib/ Drupal/ Core/ Session/ AccessPolicyProcessor.php  - AccessPolicyProcessorTest.php in core/
tests/ Drupal/ Tests/ Core/ Session/ AccessPolicyProcessorTest.php  - CacheTestTrait.php in core/
modules/ system/ tests/ src/ Traits/ CacheTestTrait.php  - DynamicPageCacheSubscriber.php in core/
modules/ dynamic_page_cache/ src/ EventSubscriber/ DynamicPageCacheSubscriber.php  - ResourceObjectNormalizationCacher.php in core/
modules/ jsonapi/ src/ EventSubscriber/ ResourceObjectNormalizationCacher.php  
3 string references to 'VariationCacheInterface'
- core.services.yml in core/
core.services.yml  - core/core.services.yml
 - dynamic_page_cache.services.yml in core/
modules/ dynamic_page_cache/ dynamic_page_cache.services.yml  - core/modules/dynamic_page_cache/dynamic_page_cache.services.yml
 - jsonapi.services.yml in core/
modules/ jsonapi/ jsonapi.services.yml  - core/modules/jsonapi/jsonapi.services.yml
 
4 services use VariationCacheInterface
- variation_cache.access_policy in core/
core.services.yml  - Drupal\Core\Cache\VariationCacheInterface
 - variation_cache.access_policy_memory in core/
core.services.yml  - Drupal\Core\Cache\VariationCacheInterface
 - variation_cache.dynamic_page_cache in core/
modules/ dynamic_page_cache/ dynamic_page_cache.services.yml  - Drupal\Core\Cache\VariationCacheInterface
 - variation_cache.jsonapi_normalizations in core/
modules/ jsonapi/ jsonapi.services.yml  - Drupal\Core\Cache\VariationCacheInterface
 
File
- 
              core/
lib/ Drupal/ Core/ Cache/ VariationCacheInterface.php, line 14  
Namespace
Drupal\Core\CacheView source
interface VariationCacheInterface {
  
  /**
   * Gets a cache entry based on cache keys.
   *
   * @param string[] $keys
   *   The cache keys to retrieve the cache entry for.
   * @param \Drupal\Core\Cache\CacheableDependencyInterface $initial_cacheability
   *   The cache metadata of the data to store before other systems had a chance
   *   to adjust it. This is also commonly known as "pre-bubbling" cacheability.
   *
   * @return object|false
   *   The cache item or FALSE on failure.
   *
   * @see \Drupal\Core\Cache\CacheBackendInterface::get()
   */
  public function get(array $keys, CacheableDependencyInterface $initial_cacheability);
  
  /**
   * Gets multiple cache entries based on a set of cache keys.
   *
   * @param array $items
   *   An associative array keyed by arbitrary identifiers. Each value is a set
   *   of arguments you would otherwise pass to ::get(). Example:
   *   @code
   *     $items = [
   *       'item_a' => [['key1', 'key2'], $cacheability_a],
   *       'item_b' => [['another_key'], $cacheability_b],
   *     ];
   *   @endcode
   *
   * @return array
   *   An associative array keyed by the same keys as $items, containing only
   *   the items found in the cache. Items that did not resolve are omitted.
   *
   * @see \Drupal\Core\Cache\VariationCacheInterface::get()
   */
  public function getMultiple(array $items) : array;
  
  /**
   * Stores data in the cache.
   *
   * @param string[] $keys
   *   The cache keys of the data to store.
   * @param mixed $data
   *   The data to store in the cache.
   * @param \Drupal\Core\Cache\CacheableDependencyInterface $cacheability
   *   The cache metadata of the data to store.
   * @param \Drupal\Core\Cache\CacheableDependencyInterface $initial_cacheability
   *   The cache metadata of the data to store before other systems had a chance
   *   to adjust it. This is also commonly known as "pre-bubbling" cacheability.
   *
   * @see \Drupal\Core\Cache\CacheBackendInterface::set()
   *
   * @throws \LogicException
   *   Thrown when cacheability is provided that does not contain a cache
   *   context or does not completely contain the initial cacheability.
   */
  public function set(array $keys, $data, CacheableDependencyInterface $cacheability, CacheableDependencyInterface $initial_cacheability) : void;
  
  /**
   * Deletes an item from the cache.
   *
   * To stay consistent with ::get(), this only affects the active variation,
   * not all possible variations for the associated cache contexts.
   *
   * @param string[] $keys
   *   The cache keys of the data to delete.
   * @param \Drupal\Core\Cache\CacheableDependencyInterface $initial_cacheability
   *   The cache metadata of the data to store before other systems had a chance
   *   to adjust it. This is also commonly known as "pre-bubbling" cacheability.
   *
   * @see \Drupal\Core\Cache\CacheBackendInterface::delete()
   */
  public function delete(array $keys, CacheableDependencyInterface $initial_cacheability) : void;
  
  /**
   * Marks a cache item as invalid.
   *
   * To stay consistent with ::get(), this only affects the active variation,
   * not all possible variations for the associated cache contexts.
   *
   * @param string[] $keys
   *   The cache keys of the data to invalidate.
   * @param \Drupal\Core\Cache\CacheableDependencyInterface $initial_cacheability
   *   The cache metadata of the data to store before other systems had a chance
   *   to adjust it. This is also commonly known as "pre-bubbling" cacheability.
   *
   * @see \Drupal\Core\Cache\CacheBackendInterface::invalidate()
   */
  public function invalidate(array $keys, CacheableDependencyInterface $initial_cacheability) : void;
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overrides | 
|---|---|---|---|---|
| VariationCacheInterface::delete | public | function | Deletes an item from the cache. | 1 | 
| VariationCacheInterface::get | public | function | Gets a cache entry based on cache keys. | 1 | 
| VariationCacheInterface::getMultiple | public | function | Gets multiple cache entries based on a set of cache keys. | 1 | 
| VariationCacheInterface::invalidate | public | function | Marks a cache item as invalid. | 1 | 
| VariationCacheInterface::set | public | function | Stores data in the cache. | 1 | 
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.