mergeMaxAges example

return $tags;
  }

  /** * Gets the max age for the current view. * * @return int */
  public function getCacheMaxAge() {
    $max_age = $this->getDefaultCacheMaxAge();
    $max_age = Cache::mergeMaxAges($max_age$this->view->getQuery()->getCacheMaxAge());
    return $max_age;
  }

  /** * Returns the default cache max age. */
  protected function getDefaultCacheMaxAge() {
    // The default cache backend is not caching anything.     return 0;
  }

  

  protected function __construct(Provider $provider = NULL, $title = NULL, $author_name = NULL, $author_url = NULL, $cache_age = NULL, $thumbnail_url = NULL, $thumbnail_width = NULL, $thumbnail_height = NULL) {
    $this->provider = $provider;
    $this->title = $title;
    $this->authorName = $author_name;
    $this->authorUrl = $author_url;

    if (isset($cache_age) && is_numeric($cache_age)) {
      // If the cache age is too big, it can overflow the 'expire' column of       // database cache backends, causing SQL exceptions. To prevent that,       // arbitrarily limit the cache age to 5 years. That should be enough.       $this->cacheMaxAge = Cache::mergeMaxAges((int) $cache_age, 157680000);
    }

    if ($thumbnail_url) {
      $this->thumbnailUrl = $thumbnail_url;
      $this->setThumbnailDimensions($thumbnail_width$thumbnail_height);
    }
  }

  /** * Creates a link resource. * * @param string $url * (optional) The URL of the resource. * @param \Drupal\media\OEmbed\Provider $provider * (optional) The resource provider. * @param string $title * (optional) A text title, describing the resource. * @param string $author_name * (optional) The name of the author/owner of the resource. * @param string $author_url * (optional) A URL for the author/owner of the resource. * @param int $cache_age * (optional) The suggested cache lifetime for this resource, in seconds. * @param string $thumbnail_url * (optional) A URL to a thumbnail image representing the resource. If this * parameter is present, $thumbnail_width and $thumbnail_height must also be * present. * @param int $thumbnail_width * (optional) The width of the thumbnail, in pixels. If this parameter is * present, $thumbnail_url and $thumbnail_height must also be present. * @param int $thumbnail_height * (optional) The height of the thumbnail, in pixels. If this parameter is * present, $thumbnail_url and $thumbnail_width must also be present. * * @return static */
/** * {@inheritdoc} */
  public function getCacheMaxAge() {
    $max_age = Cache::PERMANENT;

    // Applied contexts can affect the cache max age when this plugin is     // involved in caching, collect and return them.     foreach ($this->getContexts() as $context) {
      /** @var \Drupal\Core\Cache\CacheableDependencyInterface $context */
      if ($context instanceof CacheableDependencyInterface) {
        $max_age = Cache::mergeMaxAges($max_age$context->getCacheMaxAge());
      }
    }
    return $max_age;
  }

}


    return $tags;
  }

  /** * {@inheritdoc} */
  public function getCacheMaxAge() {
    $max_age = parent::getCacheMaxAge();
    foreach ($this->getAllEntities() as $entity) {
      $max_age = Cache::mergeMaxAges($max_age$entity->getCacheMaxAge());
    }

    return $max_age;
  }

  /** * Gets all the involved entities of the view. * * @return \Drupal\Core\Entity\EntityInterface[] */
  protected function getAllEntities() {
    
$this->operator = $break->operator;
  }

  /** * {@inheritdoc} */
  public function getCacheMaxAge() {
    $max_age = Cache::PERMANENT;

    // Asks all subplugins (argument defaults, argument validator and styles).     if (($plugin = $this->getPlugin('argument_default')) && $plugin instanceof CacheableDependencyInterface) {
      $max_age = Cache::mergeMaxAges($max_age$plugin->getCacheMaxAge());
    }

    if (($plugin = $this->getPlugin('argument_validator')) && $plugin instanceof CacheableDependencyInterface) {
      $max_age = Cache::mergeMaxAges($max_age$plugin->getCacheMaxAge());
    }

    // Summaries use style plugins.     if (($plugin = $this->getPlugin('style')) && $plugin instanceof CacheableDependencyInterface) {
      $max_age = Cache::mergeMaxAges($max_age$plugin->getCacheMaxAge());
    }

    

  protected function mergeCacheabilityFromConditions(AccessResult $access, array $conditions) {
    foreach ($conditions as $condition) {
      if ($condition instanceof CacheableDependencyInterface) {
        $access->addCacheTags($condition->getCacheTags());
        $access->addCacheContexts($condition->getCacheContexts());
        $access->setCacheMaxAge(Cache::mergeMaxAges($access->getCacheMaxAge()$condition->getCacheMaxAge()));
      }
    }
  }

}
60, 60, Cache::PERMANENT, Cache::PERMANENT],
      [60, Cache::PERMANENT, Cache::PERMANENT, 60],
    ];
  }

  /** * @covers ::mergeMaxAges * * @dataProvider mergeMaxAgesProvider */
  public function testMergeMaxAges($expected, ...$max_ages) {
    $this->assertSame($expected, Cache::mergeMaxAges(...$max_ages));
  }

  /** * Provides a list of pairs of cache contexts arrays to be merged. * * @return array */
  public function mergeCacheContextsProvide() {
    return [
      [[][][]],
      [['foo'][]['foo']],
      [[

  protected function applyDisplayCacheabilityMetadata(array &$element) {
    /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache */
    $cache = $this->getPlugin('cache');

    (new CacheableMetadata())
      ->setCacheTags(Cache::mergeTags($this->view->getCacheTags()$this->display['cache_metadata']['tags'] ?? []))
      ->setCacheContexts($this->display['cache_metadata']['contexts'] ?? [])
      ->setCacheMaxAge(Cache::mergeMaxAges($cache->getCacheMaxAge()$this->display['cache_metadata']['max-age'] ?? Cache::PERMANENT))
      ->merge(CacheableMetadata::createFromRenderArray($element))
      ->applyTo($element);
  }

  /** * {@inheritdoc} */
  public function elementPreRender(array $element) {
    $view = $element['#view'];
    $empty = empty($view->result);

    

  public function inheritCacheability(AccessResultInterface $other) {
    $this->addCacheableDependency($other);
    if ($other instanceof CacheableDependencyInterface) {
      if ($this->getCacheMaxAge() !== 0 && $other->getCacheMaxAge() !== 0) {
        $this->setCacheMaxAge(Cache::mergeMaxAges($this->getCacheMaxAge()$other->getCacheMaxAge()));
      }
      else {
        $this->setCacheMaxAge($other->getCacheMaxAge());
      }
    }
    return $this;
  }

}
else {
      $result->cacheTags = Cache::mergeTags($this->cacheTags, $other->cacheTags);
    }

    if ($this->cacheMaxAge === Cache::PERMANENT) {
      $result->cacheMaxAge = $other->cacheMaxAge;
    }
    elseif ($other->cacheMaxAge === Cache::PERMANENT) {
      $result->cacheMaxAge = $this->cacheMaxAge;
    }
    else {
      $result->cacheMaxAge = Cache::mergeMaxAges($this->cacheMaxAge, $other->cacheMaxAge);
    }
    return $result;
  }

  /** * Applies the values of this CacheableMetadata object to a render array. * * @param array &$build * A render array. */
  public function applyTo(array &$build) {
    
public function addCacheTags(array $cache_tags) {
    if ($cache_tags) {
      $this->cacheTags = Cache::mergeTags($this->cacheTags, $cache_tags);
    }
    return $this;
  }

  /** * {@inheritdoc} */
  public function mergeCacheMaxAge($max_age) {
    $this->cacheMaxAge = Cache::mergeMaxAges($this->cacheMaxAge, $max_age);
    return $this;
  }

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