You are here

function ad_cache_file_open in Advertisement 5.2

Same name and namespace in other branches
  1. 6.3 cache/file/ad_cache_file.inc \ad_cache_file_open()
  2. 6.2 cache/file/ad_cache_file.inc \ad_cache_file_open()
  3. 7 cache/file/ad_cache_file.inc \ad_cache_file_open()

Initialization function. Loads cache from file into memory.

File

cache/file/ad_cache_file.inc, line 15
A plug in for the ad.module, providing a file cache mechanism for improved performance when displaying ads.

Code

function ad_cache_file_open() {
  _debug_echo('File cache: open');
  $cache_file = ad_cache_file_get_lock();
  if ($cache_file) {

    // Read cache from disk into memory.
    $cache = unserialize(fread(adserve_variable('fd'), filesize($cache_file)));

    // Store cache in a static variable for re-use by other functions.
    ad_cache_file_cache($cache);
  }
  if (adserve_variable('debug')) {
    $last_sync = $cache['last_sync'];
    $lifetime = $cache['lifetime'];
    $time = time();
    echo "File cache: last sync: {$last_sync}<br />\n";
    echo "File cache: current time: {$time}<br />\n";
    if ($last_sync < $time - $lifetime) {
      echo "File cache: will resync cache now.<br />\n";
    }
    else {
      $seconds = $last_sync - $time + $lifetime;
      echo "File cache: will resync cache in {$seconds} seconds.<br/>\n";
    }
  }
}