You are here

public function MetatagViewsCacheWrapper::cacheGet in Metatag 8

Retrieve data from the cache.

A plugin should override this to provide specialized caching behavior.

Parameters

$type: The cache type, either 'query', 'result'.

Return value

bool TRUE if data has been taken from the cache, otherwise FALSE.

Overrides CachePluginBase::cacheGet

File

metatag_views/src/MetatagViewsCacheWrapper.php, line 87

Class

MetatagViewsCacheWrapper
This class wraps a Views cache plugin.

Namespace

Drupal\metatag_views

Code

public function cacheGet($type) {
  if ($type === self::RESULTS) {
    $cutoff = $this->plugin
      ->cacheExpire($type);

    // Values to set: $view->result, $view->total_rows, $view->execute_time,
    // $view->current_page and pass row tokens to metatag display extender.
    if ($cache = \Drupal::cache($this->plugin->resultsBin)
      ->get($this->plugin
      ->generateResultsKey())) {
      if (!$cutoff || $cache->created > $cutoff) {
        $view = $this->plugin->view;
        $view->result = $cache->data['result'];

        // Load entities for each result.
        $view->query
          ->loadEntities($view->result);
        $view->total_rows = $cache->data['total_rows'];
        $view
          ->setCurrentPage($cache->data['current_page'], TRUE);
        $view->execute_time = 0;
        $extenders = $view
          ->getDisplay()
          ->getExtenders();
        if (isset($extenders['metatag_display_extender'])) {
          $extenders['metatag_display_extender']
            ->setFirstRowTokens($cache->data['first_row_tokens']);
        }
        return TRUE;
      }
    }
    return FALSE;
  }
  return $this->plugin
    ->cacheGet($type);
}