You are here

public function RenderCacheBackendAdapter::getMultiple in Render cache 7.2

Gets multiple cache entries based on the cache info map.

Parameters

array $cache_info_map: The cache information map, keyed by ID, consisting of cache info structs.

Return value

array The builded render array, keyed by ID for each cache entry found.

Overrides RenderCacheBackendAdapterInterface::getMultiple

1 call to RenderCacheBackendAdapter::getMultiple()
RenderCacheBackendAdapter::get in src/Cache/RenderCacheBackendAdapter.php
Gets a cache entry based on the given cache info.

File

src/Cache/RenderCacheBackendAdapter.php, line 65
Contains \Drupal\render_cache\Cache\RenderCacheBackendAdapter

Class

RenderCacheBackendAdapter
Defines the render_cache.cache service.

Namespace

Drupal\render_cache\Cache

Code

public function getMultiple(array $cache_info_map) {
  $build = array();
  $cid_map_per_bin = array();
  foreach ($cache_info_map as $id => $cache_info) {
    $bin = isset($cache_info['bin']) ? $cache_info['bin'] : 'cache';
    $cid = $this
      ->getCacheId($cache_info);
    $cid_map_per_bin[$bin][$cid] = $id;
  }
  foreach ($cid_map_per_bin as $bin => $cid_map) {

    // Retrieve data from the cache.
    $cids = array_filter(array_keys($cid_map));
    if (!empty($cids)) {
      $cached = $this
        ->cache($bin)
        ->getMultiple($cids);
      foreach ($cached as $cid => $cache) {
        if (!$cache) {
          continue;
        }
        $id = $cid_map[$cid];
        $render = $this->renderStack
          ->convertRenderArrayFromD7($cache->data);

        // @codeCoverageIgnoreStart
        if (!$this
          ->validate($render)) {
          $cache_strategy = $cache_info_map[$id]['render_cache_cache_strategy'];

          // We need to clear the cache for the late rendering strategy, else
          // drupal_render_cache_get() will retrieve the item again from the
          // cache.
          if ($cache_strategy == RenderCache::RENDER_CACHE_STRATEGY_LATE_RENDER) {
            $this
              ->cache($bin)
              ->clear($cid);
          }
          continue;
        }

        // @codeCoverageIgnoreEnd
        $build[$id] = $render;
      }
    }
  }
  return $build;
}