addCacheMetadata example

$displays = $this->get('display');

    // Sort the displays.     ksort($displays);
    $this->set('display', ['default' => $displays['default']] + $displays);

    // Calculating the cacheability metadata is only needed when the view is     // saved through the UI or API. It should not be done when we are syncing     // configuration or installing modules.     if (!$this->isSyncing() && !$this->hasTrustedData()) {
      $this->addCacheMetadata();
    }
  }

  /** * Fills in the cache metadata of this view. * * Cache metadata is set per view and per display, and ends up being stored in * the view's configuration. This allows Views to determine very efficiently: * - the max-age * - the cache contexts * - the cache tags * * In other words: this allows us to do the (expensive) work of initializing * Views plugins and handlers to determine their effect on the cacheability of * a view at save time rather than at runtime. */
Home | Imprint | This part of the site doesn't use cookies.