You are here

function cache_get in Drupal 4

Same name and namespace in other branches
  1. 5 includes/cache.inc \cache_get()
  2. 6 includes/cache.inc \cache_get()
  3. 6 includes/cache-install.inc \cache_get()
  4. 7 includes/cache.inc \cache_get()

Return data from the persistent cache.

Parameters

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

6 calls to cache_get()
archive_calendar in modules/archive.module
Generates a monthly calendar, for display in the archive block.
check_markup in modules/filter.module
Run all the enabled filters on a piece of text.
locale in modules/locale.module
Provides interface translation services.
menu_get_menu in includes/menu.inc
Return the menu data structure.
page_get_cache in includes/bootstrap.inc
Retrieve the current page from the cache.

... See full list

File

includes/bootstrap.inc, line 320
Functions that need to be loaded on every Drupal request.

Code

function cache_get($key) {
  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()) {

    // Time to flush old cache data
    db_query("DELETE FROM {cache} WHERE expire != %d AND expire <= %d", CACHE_PERMANENT, $cache_flush);
    variable_set('cache_flush', 0);
  }
  $cache = db_fetch_object(db_query("SELECT data, created, headers, expire FROM {cache} WHERE cid = '%s'", $key));
  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);
    }
    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);
      }
    }
    return $cache;
  }
  return 0;
}