function public function Theme::getCache

8.x-3.x Theme.php public Theme::getCache($name, array $context = [], $default = [])

Retrieves an individual item from a theme's cache in the database.

Parameters

string $name: The name of the item to retrieve from the theme cache.

array $context: Optional. An array of additional context to use for retrieving the cached storage.

mixed $default: Optional. The default value to use if $name does not exist.

Return value

mixed|\Drupal\bootstrap\Utility\StorageItem The cached value for $name.

Class

Theme
Defines a theme object.

Namespace

Drupal\bootstrap

Source src/Theme.php (line 393)

public function getCache($name, array $context = [], $default = []) {
  static $cache = [];

  // Prepend the theme name as the first context item, followed by cache name.
  array_unshift($context, $name);
  array_unshift($context, $this->getName());

  // Join context together with ":" and use it as the name.
  $name = implode(':', $context);

  if (!isset($cache[$name])) {
    $storage = self::getStorage();
    $value = $storage->get($name);
    if (!isset($value)) {
      $value = is_array($default) ? new StorageItem($default, $storage) : $default;
      $storage->set($name, $value);
    }
    $cache[$name] = $value;
  }

  return $cache[$name];
}