function ContextAwarePluginBase::getCacheMaxAge

Overrides CacheableDependencyInterface::getCacheMaxAge

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.