getCacheMetadata example

$key_data = [
        'build_info' => $build_info,
      ];
      // @todo https://www.drupal.org/node/2433591 might solve it to not require       // the pager information here.       $key_data['pager'] = [
        'page' => $this->view->getCurrentPage(),
        'items_per_page' => $this->view->getItemsPerPage(),
        'offset' => $this->view->getOffset(),
      ];
      $key_data += \Drupal::service('cache_contexts_manager')->convertTokensToKeys($this->displayHandler->getCacheMetadata()->getCacheContexts())->getKeys();

      $this->resultsKey = $this->view->storage->id() . ':' . $this->displayHandler->display['id'] . ':results:' . hash('sha256', serialize($key_data));
    }

    return $this->resultsKey;
  }

  /** * Gets an array of cache tags for the current view. * * @return string[] * An array of cache tags based on the current view. */
$container->get('renderer'),
      $container->get('language.default'),
      $container->get('language_manager'),
      $container->get('string_translation')
    );
  }

  /** * {@inheritdoc} */
  public function getCacheTags() {
    return $this->getCacheMetadata()->getCacheTags();
  }

  /** * {@inheritdoc} */
  public function getCacheContexts() {
    return $this->getCacheMetadata()->getCacheContexts();
  }

  /** * {@inheritdoc} */

class ViewsExposedFilterBlock extends ViewsBlockBase {

  /** * {@inheritdoc} */
  public function getCacheContexts() {
    $contexts = $this->view->display_handler->getCacheMetadata()->getCacheContexts();
    return Cache::mergeContexts(parent::getCacheContexts()$contexts);
  }

  /** * {@inheritdoc} * * @return array * A renderable array representing the content of the block with additional * context of current view and display ID. */
  public function build() : array {
    
Home | Imprint | This part of the site doesn't use cookies.