function Cache::mergeMaxAges

Same name in other branches
  1. 9 core/lib/Drupal/Core/Cache/Cache.php \Drupal\Core\Cache\Cache::mergeMaxAges()
  2. 10 core/lib/Drupal/Core/Cache/Cache.php \Drupal\Core\Cache\Cache::mergeMaxAges()
  3. 11.x core/lib/Drupal/Core/Cache/Cache.php \Drupal\Core\Cache\Cache::mergeMaxAges()

Merges max-age values (expressed in seconds), finds the lowest max-age.

Ensures infinite max-age (Cache::PERMANENT) is taken into account.

Parameters

int $a: Max age value to merge.

int $b: Max age value to merge.

Return value

int The minimum max-age value.

10 calls to Cache::mergeMaxAges()
AccessResult::inheritCacheability in core/lib/Drupal/Core/Access/AccessResult.php
Inherits the cacheability of the other access result, if any.
ArgumentPluginBase::getCacheMaxAge in core/modules/views/src/Plugin/views/argument/ArgumentPluginBase.php
The maximum age for which this object may be cached.
BlockAccessControlHandler::mergeCacheabilityFromConditions in core/modules/block/src/BlockAccessControlHandler.php
Merges cacheable metadata from conditions onto the access result object.
CacheableMetadata::merge in core/lib/Drupal/Core/Cache/CacheableMetadata.php
Merges the values of another CacheableMetadata object with this one.
CachePluginBase::getCacheMaxAge in core/modules/views/src/Plugin/views/cache/CachePluginBase.php
Gets the max age for the current view.

... See full list

File

core/lib/Drupal/Core/Cache/Cache.php, line 78

Class

Cache
Helper methods for cache.

Namespace

Drupal\Core\Cache

Code

public static function mergeMaxAges($a = Cache::PERMANENT, $b = Cache::PERMANENT) {
    // If one of the values is Cache::PERMANENT, return the other value.
    if ($a === Cache::PERMANENT) {
        return $b;
    }
    if ($b === Cache::PERMANENT) {
        return $a;
    }
    // If none or the values are Cache::PERMANENT, return the minimum value.
    return min($a, $b);
}

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