Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AbstractObjectNormalizer.php

function AbstractObjectNormalizer::getCacheKey

Builds the cache key for the attributes cache.

The key must be different for every option in the context that could change which attributes should be handled.

3 calls to AbstractObjectNormalizer::getCacheKey()
AbstractObjectNormalizer::createChildContext in vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php
Overwritten to update the cache key for the child.
AbstractObjectNormalizer::denormalize in vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php
Denormalizes data back into an object of the given class.
AbstractObjectNormalizer::normalize in vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php
Normalizes data into a set of arrays/scalars.

File

vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php, line 1077

Class

AbstractObjectNormalizer
Base class for a normalizer dealing with objects.

Namespace

Symfony\Component\Serializer\Normalizer

Code

private function getCacheKey(?string $format, array $context) : bool|string {
    foreach ($context[self::EXCLUDE_FROM_CACHE_KEY] ?? $this->defaultContext[self::EXCLUDE_FROM_CACHE_KEY] as $key) {
        unset($context[$key]);
    }
    unset($context[self::EXCLUDE_FROM_CACHE_KEY]);
    unset($context[self::OBJECT_TO_POPULATE]);
    unset($context['cache_key']);
    // avoid artificially different keys
    try {
        return hash('xxh128', $format . serialize([
            'context' => $context,
            'ignored' => $context[self::IGNORED_ATTRIBUTES] ?? $this->defaultContext[self::IGNORED_ATTRIBUTES],
        ]));
    } catch (\Exception) {
        // The context cannot be serialized, skip the cache
        return false;
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal