You are here

public static function Cache::mergeMaxAges in Drupal 9

Same name and namespace in other branches
  1. 8 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 ...: Max age values 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 69

Class

Cache
Helper methods for cache.

Namespace

Drupal\Core\Cache

Code

public static function mergeMaxAges(...$max_ages) {

  // Remove Cache::PERMANENT values to return the correct minimum value.
  $max_ages = array_filter($max_ages, function ($max_age) {
    return $max_age !== Cache::PERMANENT;
  });

  // If there are no max ages left return Cache::PERMANENT, otherwise return
  // the minimum value.
  return empty($max_ages) ? Cache::PERMANENT : min($max_ages);
}