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
- class \Drupal\Core\Cache\CacheableMetadata implements RefinableCacheableDependencyInterface uses RefinableCacheableDependencyTrait
- class \Drupal\graphql\GraphQL\Cache\CacheableValue implements ValueWrapperInterface
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
File
- src/
GraphQL/ Cache/ CacheableValue.php, line 19
Namespace
Drupal\graphql\GraphQL\CacheView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CacheableDependencyTrait:: |
protected | property | Cache contexts. | |
CacheableDependencyTrait:: |
protected | property | Cache max-age. | |
CacheableDependencyTrait:: |
protected | property | Cache tags. | |
CacheableDependencyTrait:: |
protected | function | Sets cacheability; useful for value object constructors. | |
CacheableMetadata:: |
public | function | Applies the values of this CacheableMetadata object to a render array. | 1 |
CacheableMetadata:: |
public static | function | Creates a CacheableMetadata object from a depended object. | 1 |
CacheableMetadata:: |
public static | function | Creates a CacheableMetadata object with values taken from a render array. | 1 |
CacheableMetadata:: |
public | function |
The cache contexts associated with this object. Overrides CacheableDependencyTrait:: |
|
CacheableMetadata:: |
public | function |
The maximum age for which this object may be cached. Overrides CacheableDependencyTrait:: |
|
CacheableMetadata:: |
public | function |
The cache tags associated with this object. Overrides CacheableDependencyTrait:: |
|
CacheableMetadata:: |
public | function | Merges the values of another CacheableMetadata object with this one. | 1 |
CacheableMetadata:: |
public | function | Sets cache contexts. | |
CacheableMetadata:: |
public | function | Sets the maximum age (in seconds). | |
CacheableMetadata:: |
public | function | Sets cache tags. | |
CacheableValue:: |
protected | property | The actual value being wrapped. | |
CacheableValue:: |
public | function |
Get the wrapped value. Overrides ValueWrapperInterface:: |
|
CacheableValue:: |
public | function |
Set the wrapped value. Overrides ValueWrapperInterface:: |
|
CacheableValue:: |
public | function | CacheableValue constructor. | |
RefinableCacheableDependencyTrait:: |
public | function | 1 | |
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function | ||
RefinableCacheableDependencyTrait:: |
public | function |