You are here

public function ContextAwarePluginTrait::getCacheMaxAge in Drupal 10

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php \Drupal\Core\Plugin\ContextAwarePluginTrait::getCacheMaxAge()
4 methods override ContextAwarePluginTrait::getCacheMaxAge()
AttachedRenderingBlock::getCacheMaxAge in core/modules/system/tests/modules/render_attached_test/src/Plugin/Block/AttachedRenderingBlock.php
RedirectFormBlock::getCacheMaxAge in core/modules/system/tests/modules/form_test/src/Plugin/Block/RedirectFormBlock.php
@todo Make cacheable once https://www.drupal.org/node/2351015 lands.
TestAccessBlock::getCacheMaxAge in core/modules/block/tests/modules/block_test/src/Plugin/Block/TestAccessBlock.php
TestCacheBlock::getCacheMaxAge in core/modules/block/tests/modules/block_test/src/Plugin/Block/TestCacheBlock.php

File

core/lib/Drupal/Core/Plugin/ContextAwarePluginTrait.php, line 203

Class

ContextAwarePluginTrait
Provides a trait to add context-aware functionality to plugins.

Namespace

Drupal\Core\Plugin

Code

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;
}