function RenderCache::getMultiple

Gets multiple cached, pre-rendered elements from cache.

Parameters

array $multiple_elements: An associative array keyed by arbitrary identifiers, where the value is what you would otherwise pass to ::get(). Example:

$items = [
  'item_a' => $elements_a,
  'item_b' => $elements_b,
];

Return value

array An associative array keyed by the same keys as $multiple_elements, containing the original element and all its children pre-rendered. Items whose cached copy was not available are not returned.

Overrides RenderCacheInterface::getMultiple

File

core/lib/Drupal/Core/Render/RenderCache.php, line 57

Class

RenderCache
Wraps the caching logic for the render caching system.

Namespace

Drupal\Core\Render

Code

public function getMultiple(array $multiple_elements) : array {
  if (empty($multiple_elements)) {
    return [];
  }
  $bin_map = [];
  foreach ($multiple_elements as $item_key => $elements) {
    if (!$this->isElementCacheable($elements)) {
      continue;
    }
    $bin_map[$elements['#cache']['bin'] ?? 'render'][$item_key] = [
      $elements['#cache']['keys'],
      CacheableMetadata::createFromRenderArray($elements),
    ];
  }
  $results = [];
  foreach ($bin_map as $bin => $items) {
    foreach ($this->cacheFactory
      ->get($bin)
      ->getMultiple($items) as $item_key => $cache) {
      if ($this->isCacheableForCurrentHttpMethod($cache->tags)) {
        $results[$item_key] = $cache->data;
      }
    }
  }
  return $results;
}

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