You are here

protected function D8Cache::mergeExpireWithMaxAge in Drupal 8 Cache Backport 7

Merges an max-age value with an expire timestamp.

Parameters

int $expire: A unix timestamp when this item will expire or one of the CACHE_* constants.

int $max_age: A max-age ttl value like an integer or CACHE_MAX_AGE_PERMANENT.

Return value

int A unix timestamp when this item will expire or one of the CACHE_* constants.

1 call to D8Cache::mergeExpireWithMaxAge()
D8Cache::set in ./d8cache.cache.inc

File

./d8cache.cache.inc, line 228

Class

D8Cache
Defines a Drupal 8 cacheable metadata aware cache backend.

Code

protected function mergeExpireWithMaxAge($expire, $max_age) {

  // The difference between $expire and $max-age is that while $expire is
  // a unix timestamp, $max_age is a relative TTL. So, when they interact,
  // we have to be careful to not compare apples and oranges.
  // Do not mess with temporary items.
  if ($expire == CACHE_TEMPORARY) {
    return $expire;
  }

  // In case $max_age is PERMANENT return $expire as is.
  if ($max_age === CACHE_MAX_AGE_PERMANENT) {
    return $expire;
  }

  // If $expire is permanent return the numeric ttl.
  if ($expire == CACHE_PERMANENT) {
    return REQUEST_TIME + $max_age;
  }

  // In all other cases return the minimum of ttl($expire) and $max_age.
  return REQUEST_TIME + min(REQUEST_TIME - $expire, $max_age);
}