Skip to content

Instantly share code, notes, and snippets.

@cmcintosh
Created December 1, 2019 06:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cmcintosh/40af561958519db6d098f215b5a4d028 to your computer and use it in GitHub Desktop.
Save cmcintosh/40af561958519db6d098f215b5a4d028 to your computer and use it in GitHub Desktop.
/**
* Merges max-age values (expressed in seconds), finds the lowest max-age.
*
* Ensures infinite max-age (Cache::PERMANENT) is taken into account.
*
* @param int $a
* Max age value to merge.
* @param int $b
* Max age value to merge.
*
* @return int
* The minimum max-age value.
*/
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 || $a == 0) {
return $b;
}
if ($b === Cache::PERMANENT || $b == 0) {
return $a;
}
// If none or the values are Cache::PERMANENT, return the minimum value.
return min($a, $b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment