You are here

function ajax_comments_cache_get in AJAX Comments 6

This one differs from standard by loading even expired cache instances.

1 call to ajax_comments_cache_get()
ajax_comments_form_get_cache in ./ajax_comments.pages.inc
Fetch a form from cache.

File

./ajax_comments.pages.inc, line 140
AJAX comments form handling and callbacks.

Code

function ajax_comments_cache_get($cid, $table = 'cache') {
  global $user;

  // Garbage collection necessary when enforcing a minimum cache lifetime
  $cache_flush = variable_get('cache_flush', 0);
  if ($cache_flush && $cache_flush + variable_get('cache_lifetime', 0) <= time()) {

    // Reset the variable immediately to prevent a meltdown in heavy load situations.
    variable_set('cache_flush', 0);

    // Time to flush old cache data
    // Support third-party caching systems such as CacheRouter
    if (variable_get('cache_inc', FALSE)) {
      cache_clear_all(NULL, $table);
    }
    else {
      db_query("DELETE FROM {" . $table . "} WHERE expire != %d AND expire <= %d", CACHE_PERMANENT, $cache_flush);
    }
  }

  // Support third-party caching systems such as CacheRouter
  if (variable_get('cache_inc', FALSE)) {
    $cache = cache_get($cid, $table);
    if (isset($cache->data)) {
      return $cache;
    }
  }
  else {
    $cache = db_fetch_object(db_query("SELECT data, created, headers, expire, serialized FROM {" . $table . "} WHERE cid = '%s'", $cid));
    if (isset($cache->data)) {
      $cache->data = db_decode_blob($cache->data);
      if ($cache->serialized) {
        $cache->data = unserialize($cache->data);
      }
      return $cache;
    }
  }
  return 0;
}