function ResourceObjectNormalizationCacher::get

Same name in other branches
  1. 9 core/modules/jsonapi/src/EventSubscriber/ResourceObjectNormalizationCacher.php \Drupal\jsonapi\EventSubscriber\ResourceObjectNormalizationCacher::get()
  2. 8.9.x core/modules/jsonapi/src/EventSubscriber/ResourceObjectNormalizationCacher.php \Drupal\jsonapi\EventSubscriber\ResourceObjectNormalizationCacher::get()
  3. 11.x core/modules/jsonapi/src/EventSubscriber/ResourceObjectNormalizationCacher.php \Drupal\jsonapi\EventSubscriber\ResourceObjectNormalizationCacher::get()

Reads an entity normalization from cache.

The returned normalization may only be a partial normalization because it was previously normalized with a sparse fieldset.

Parameters

\Drupal\jsonapi\JsonApiResource\ResourceObject $object: The resource object for which to generate a cache item.

Return value

array|false The cached normalization parts, or FALSE if not yet cached.

See also

\Drupal\dynamic_page_cache\EventSubscriber\DynamicPageCacheSubscriber::renderArrayToResponse()

File

core/modules/jsonapi/src/EventSubscriber/ResourceObjectNormalizationCacher.php, line 97

Class

ResourceObjectNormalizationCacher
Caches entity normalizations after the response has been sent.

Namespace

Drupal\jsonapi\EventSubscriber

Code

public function get(ResourceObject $object) {
    // @todo Investigate whether to cache POST and PATCH requests.
    // @todo Follow up on https://www.drupal.org/project/drupal/issues/3381898.
    if (!$this->requestStack
        ->getCurrentRequest()
        ->isMethodCacheable()) {
        return FALSE;
    }
    $cached = $this->variationCache
        ->get($this->generateCacheKeys($object), new CacheableMetadata());
    return $cached ? $cached->data : FALSE;
}

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