You are here

function ad_cache_file_open in Advertisement 6.2

Same name and namespace in other branches
  1. 5.2 cache/file/ad_cache_file.inc \ad_cache_file_open()
  2. 6.3 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.

1 call to ad_cache_file_open()
ad_cache_file_cron in cache/file/ad_cache_file.module
Implementation of hook_adcacheapi().

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 (adserve_variable('ad_cache_file_rebuild_realtime')) {
      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";
      }
    }
    else {
      if ($last_sync < $time - $lifetime) {
        echo "File cache: cron will resync cache the next time it runs.<br />\n";
      }
      else {
        $seconds = $last_sync - $time + $lifetime;
        echo "File cache: cron will resync cache after {$seconds} seconds.<br/>\n";
      }
    }
  }
}