You are here

function cache_get in Flush page cache 6

Return data from the persistent cache. Data may be stored as either plain text or as serialized data. cache_get will automatically return unserialized objects and arrays.

Parameters

$cid: The cache ID of the data to retrieve.

$table: The table $table to store the data in. Valid core values are 'cache_filter', 'cache_menu', 'cache_page', or 'cache' for the default cache.

1 call to cache_get()
flush_page_cache_test_object_cache_disabled in ./flush_page_cache.module
Test that the object cache is being correctly disabled and flushed.

File

./flush_page_cache.cache.inc, line 13

Code

function cache_get($cid, $table = 'cache') {

  // Handle flush page cache request by deleting the cached object and returning FALSE.
  if (function_exists('flush_page_cache_requested') && flush_page_cache_requested()) {
    return 0;
  }
  global $user;

  // Garbage collection necessary when enforcing a minimum cache lifetime
  $cache_flush = variable_get('cache_flush_' . $table, 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_' . $table, 0);

    // Time to flush old cache data
    db_query("DELETE FROM {" . $table . "} WHERE expire != %d AND expire <= %d", CACHE_PERMANENT, $cache_flush);
  }
  $cache = db_fetch_object(db_query("SELECT data, created, headers, expire, serialized FROM {" . $table . "} WHERE cid = '%s'", $cid));
  if (isset($cache->data)) {

    // If the data is permanent or we're not enforcing a minimum cache lifetime
    // always return the cached data.
    if ($cache->expire == CACHE_PERMANENT || !variable_get('cache_lifetime', 0)) {
      $cache->data = db_decode_blob($cache->data);
      if ($cache->serialized) {
        $cache->data = unserialize($cache->data);
      }
    }
    else {
      if (isset($user->cache) && $user->cache > $cache->created) {

        // This cache data is too old and thus not valid for us, ignore it.
        return 0;
      }
      else {
        $cache->data = db_decode_blob($cache->data);
        if ($cache->serialized) {
          $cache->data = unserialize($cache->data);
        }
      }
    }
    return $cache;
  }
  return 0;
}