getRowCacheKeys example

          // need individual field markup to support proper theming, we build           // a raw render array containing all field render arrays and cache it.           // This allows us to cache the markup of the various children, that is           // individual fields, which is then available for style template           // preprocess functions, later in the rendering workflow.           // @todo Fetch all the available cached row items in one single cache           // get operation, once https://www.drupal.org/node/2453945 is fixed.           $data = [
            '#pre_render' => [[$this, 'elementPreRenderRow']],
            '#row' => $row,
            '#cache' => [
              'keys' => $cache_plugin->getRowCacheKeys($row),
              'tags' => $cache_plugin->getRowCacheTags($row),
              'max-age' => $max_age,
            ],
            '#cache_properties' => $field_ids,
          ];
          $renderer->addCacheableDependency($data$this->view->storage);
          // Views may be rendered both inside and outside a render context:           // - HTML views are rendered inside a render context: then we want to           // use ::render(), so that attachments and cacheability are bubbled.           // - non-HTML views are rendered outside a render context: then we           // want to use ::renderPlain(), so that no bubbling happens
$view = Views::getView('test_row_render_cache_none');
    $view->setDisplay();
    $view->preview();

    /** @var \Drupal\Core\Render\RenderCacheInterface $render_cache */
    $render_cache = $this->container->get('render_cache');

    /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache_plugin */
    $cache_plugin = $view->display_handler->getPlugin('cache');

    foreach ($view->result as $row) {
      $keys = $cache_plugin->getRowCacheKeys($row);
      $cache = [
        '#cache' => [
          'keys' => $keys,
          'contexts' => ['languages:language_interface', 'theme', 'user.permissions'],
        ],
      ];
      $element = $render_cache->get($cache);
      $this->assertFalse($element);
    }
  }

  
Home | Imprint | This part of the site doesn't use cookies.