generateResultsKey example

'table' => 'views_test_data',
        'field' => 'name',
        'operator' => '=',
        'value' => 'John',
        'group' => 0,
      ],
    ]);

    $this->executeView($view);

    // Get the cache item.     $cid1 = $view->display_handler->getPlugin('cache')->generateResultsKey();

    // Build the expected result.     $dataset = [['name' => 'John']];

    // Verify the result.     $this->assertCount(1, $view->result, 'The number of returned rows match.');
    $this->assertIdenticalResultSet($view$dataset[
      'views_test_data_name' => 'name',
    ]);

    $view->destroy();

    
case 'query':
        // Not supported currently, but this is certainly where we'd put it.         break;

      case 'results':
        $data = [
          'result' => $this->prepareViewResult($this->view->result),
          'total_rows' => $this->view->total_rows ?? 0,
          'current_page' => $this->view->getCurrentPage(),
        ];
        $expire = ($this->cacheSetMaxAge($type) === Cache::PERMANENT) ? Cache::PERMANENT : (int) $this->view->getRequest()->server->get('REQUEST_TIME') + $this->cacheSetMaxAge($type);
        \Drupal::cache($this->resultsBin)->set($this->generateResultsKey()$data$expire$this->getCacheTags());
        break;
    }
  }

  /** * Retrieve data from the cache. * * A plugin should override this to provide specialized caching behavior. * * @param $type * The cache type, either 'query', 'result'. * * @return bool * TRUE if data has been taken from the cache, otherwise FALSE. */
$this->assertEqualsCanonicalizing($expected_render_array_cache_tags$build['#cache']['tags']);

    if ($views_caching_is_enabled) {
      // Check Views render cache item cache tags.       /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache_plugin */
      $cache_plugin = $view->display_handler->getPlugin('cache');

      // Results cache.
      // Ensure that the views query is built.       $view->build();
      $results_cache_item = \Drupal::cache('data')->get($cache_plugin->generateResultsKey());
      if (is_array($expected_results_cache)) {
        $this->assertNotEmpty($results_cache_item, 'Results cache item found.');
        if ($results_cache_item) {
          $this->assertEqualsCanonicalizing($expected_results_cache$results_cache_item->tags);
        }
      }
      else {
        $this->assertNull($results_cache_item, 'Results cache item not found.');
      }

      // Check Views render cache item cache tags.
Home | Imprint | This part of the site doesn't use cookies.