function ContextAwarePluginBase::getCacheMaxAge

4 calls to ContextAwarePluginBase::getCacheMaxAge()
TestCacheBlock::getCacheMaxAge in core/modules/block/tests/modules/block_test/src/Plugin/Block/TestCacheBlock.php
TestCacheBlock::getCacheMaxAge in core/modules/block/tests/modules/block_test/src/Plugin/Block/TestCacheBlock.php
TestCacheBlock::getCacheMaxAge in core/modules/block/tests/modules/block_test/src/Plugin/Block/TestCacheBlock.php
TestCacheBlock::getCacheMaxAge in core/modules/block/tests/modules/block_test/src/Plugin/Block/TestCacheBlock.php
1 method overrides ContextAwarePluginBase::getCacheMaxAge()
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.

File

core/lib/Drupal/Core/Plugin/ContextAwarePluginBase.php, line 162

Class

ContextAwarePluginBase
Base class for plugins that are context aware.

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 $context \Drupal\Core\Cache\CacheableDependencyInterface */
    if ($context instanceof CacheableDependencyInterface) {
      $max_age = Cache::mergeMaxAges($max_age, $context->getCacheMaxAge());
    }
  }
  return $max_age;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.