You are here

public function ContextAwarePluginBase::getCacheMaxAge in Drupal 8

The maximum age for which this object may be cached.

Return value

int The maximum time in seconds that this object may be cached.

Overrides CacheableDependencyInterface::getCacheMaxAge

1 call to ContextAwarePluginBase::getCacheMaxAge()
TestCacheBlock::getCacheMaxAge in core/modules/block/tests/modules/block_test/src/Plugin/Block/TestCacheBlock.php
The maximum age for which this object may be cached.
7 methods override ContextAwarePluginBase::getCacheMaxAge()
AttachedRenderingBlock::getCacheMaxAge in core/modules/system/tests/modules/render_attached_test/src/Plugin/Block/AttachedRenderingBlock.php
The maximum age for which this object may be cached.
BookNavigationBlock::getCacheMaxAge in core/modules/book/src/Plugin/Block/BookNavigationBlock.php
@todo Make cacheable in https://www.drupal.org/node/2483181
LanguageBlock::getCacheMaxAge in core/modules/language/src/Plugin/Block/LanguageBlock.php
@todo Make cacheable in https://www.drupal.org/node/2232375.
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.
SystemMessagesBlock::getCacheMaxAge in core/modules/system/src/Plugin/Block/SystemMessagesBlock.php
The maximum age for which this object may be cached.

... See full list

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