Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ContextAwarePluginTrait.php

function ContextAwarePluginTrait::getCacheMaxAge

2 methods override ContextAwarePluginTrait::getCacheMaxAge()
LanguageBlock::getCacheMaxAge in core/modules/language/src/Plugin/Block/LanguageBlock.php
@todo Make cacheable in https://www.drupal.org/node/2232375.
SystemMessagesBlock::getCacheMaxAge in core/modules/system/src/Plugin/Block/SystemMessagesBlock.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;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal