class ContextCacheKeys

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

A value object to store generated cache keys with its cacheability metadata.

Hierarchy

Expanded class hierarchy of ContextCacheKeys

1 file declares its use of ContextCacheKeys
RendererTestBase.php in core/tests/Drupal/Tests/Core/Render/RendererTestBase.php
Contains \Drupal\Tests\Core\Render\RendererTestBase.

File

core/lib/Drupal/Core/Cache/Context/ContextCacheKeys.php, line 10

Namespace

Drupal\Core\Cache\Context
View source
class ContextCacheKeys extends CacheableMetadata {
  
  /**
   * The generated cache keys.
   *
   * @var string[]
   */
  protected $keys;
  
  /**
   * Constructs a ContextCacheKeys object.
   *
   * @param string[] $keys
   *   The cache context keys.
   */
  public function __construct(array $keys) {
    // Domain invariant: cache keys must be always sorted.
    // Sorting keys warrants that different combination of the same keys
    // generates the same cache cid.
    // @see \Drupal\Core\Render\RenderCache::createCacheID()
    sort($keys);
    $this->keys = $keys;
  }
  
  /**
   * Gets the generated cache keys.
   *
   * @return string[]
   *   The cache keys.
   */
  public function getKeys() {
    return $this->keys;
  }

}

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