You are here

function oembed_cache_expire in oEmbed 7

Helper function to calculate expire based on lifetime and cache age.

Parameters

$embed:

Return value

mixed|null

1 call to oembed_cache_expire()
oembed_oembed_fetch in ./oembed.module
oEmbed fetcher and parser.

File

./oembed.module, line 286
Core functionality for oEmbed

Code

function oembed_cache_expire($embed) {

  // If expire is not set, use default value and adjust for request time.
  $lifetime = variable_get('oembed_cache_lifetime', 3600);

  // Recalculate cache expire time based on response.
  if ($lifetime != CACHE_PERMANENT && isset($embed['cache_age'])) {
    $lifetime = max($lifetime, intval($embed['cache_age']));
  }
  if ($lifetime == CACHE_PERMANENT) {
    $expire = $lifetime;
  }
  else {

    // Twitter returns an unreasonably high cache_age of 31536000000 seconds,
    // which is longer than the expire column in Drupal cache table supports.
    $expire = min($lifetime + REQUEST_TIME, pow(2, 31));
  }
  return $expire;
}