You are here

class CacheableValue in GraphQL 8.3

Wrapper class for transporting cache metadata for resolved values.

In some cases, especially when resolving leaf (scalar / null) values, the yielded values can't transport any cache metadata themselves. In these cases, you can use this wrapper to decorate your resolved values with cache metadata without having to implement a custom class.

Hierarchy

Expanded class hierarchy of CacheableValue

See also

\Drupal\Core\Cache\RefinableCacheableDependencyInterface

17 files declare their use of CacheableValue
BlocksByRegion.php in modules/graphql_core/src/Plugin/GraphQL/Fields/Blocks/BlocksByRegion.php
Breadcrumbs.php in modules/graphql_core/src/Plugin/GraphQL/Fields/Breadcrumbs/Breadcrumbs.php
EntityById.php in modules/graphql_core/src/Plugin/GraphQL/Fields/Entity/EntityById.php
EntityField.php in modules/graphql_core/src/Plugin/GraphQL/Fields/Entity/EntityField.php
EntityQueryEntities.php in modules/graphql_core/src/Plugin/GraphQL/Fields/EntityQuery/EntityQueryEntities.php

... See full list

File

src/GraphQL/Cache/CacheableValue.php, line 19

Namespace

Drupal\graphql\GraphQL\Cache
View source
class CacheableValue extends CacheableMetadata implements ValueWrapperInterface {

  /**
   * @var mixed
   *   The actual value being wrapped.
   */
  protected $value;

  /**
   * CacheableValue constructor.
   *
   * @param mixed $value
   *   The actual value to be wrapped.
   * @param array $dependencies
   *   An array of cache dependencies.
   */
  public function __construct($value, array $dependencies = []) {
    $this->value = $value;
    if ($value instanceof CacheableDependencyInterface) {
      $this
        ->addCacheableDependency($value);
    }
    foreach ($dependencies as $dependency) {
      if ($dependency instanceof CacheableDependencyInterface) {
        $this
          ->addCacheableDependency($dependency);
      }
    }
  }

  /**
   * {@inheritdoc}
   */
  public function setValue($value) {
    $this->value = $value;
  }

  /**
   * {@inheritdoc}
   */
  public function getValue() {
    return $this->value;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CacheableDependencyTrait::$cacheContexts protected property Cache contexts.
CacheableDependencyTrait::$cacheMaxAge protected property Cache max-age.
CacheableDependencyTrait::$cacheTags protected property Cache tags.
CacheableDependencyTrait::setCacheability protected function Sets cacheability; useful for value object constructors.
CacheableMetadata::applyTo public function Applies the values of this CacheableMetadata object to a render array. 1
CacheableMetadata::createFromObject public static function Creates a CacheableMetadata object from a depended object. 1
CacheableMetadata::createFromRenderArray public static function Creates a CacheableMetadata object with values taken from a render array. 1
CacheableMetadata::getCacheContexts public function The cache contexts associated with this object. Overrides CacheableDependencyTrait::getCacheContexts
CacheableMetadata::getCacheMaxAge public function The maximum age for which this object may be cached. Overrides CacheableDependencyTrait::getCacheMaxAge
CacheableMetadata::getCacheTags public function The cache tags associated with this object. Overrides CacheableDependencyTrait::getCacheTags
CacheableMetadata::merge public function Merges the values of another CacheableMetadata object with this one. 1
CacheableMetadata::setCacheContexts public function Sets cache contexts.
CacheableMetadata::setCacheMaxAge public function Sets the maximum age (in seconds).
CacheableMetadata::setCacheTags public function Sets cache tags.
CacheableValue::$value protected property The actual value being wrapped.
CacheableValue::getValue public function Get the wrapped value. Overrides ValueWrapperInterface::getValue
CacheableValue::setValue public function Set the wrapped value. Overrides ValueWrapperInterface::setValue
CacheableValue::__construct public function CacheableValue constructor.
RefinableCacheableDependencyTrait::addCacheableDependency public function 1
RefinableCacheableDependencyTrait::addCacheContexts public function
RefinableCacheableDependencyTrait::addCacheTags public function
RefinableCacheableDependencyTrait::mergeCacheMaxAge public function