cache_set

Versions
4.6 – 4.7
cache_set($cid, $data, $expire = CACHE_PERMANENT, $headers = NULL)
5
cache_set($cid, $table = 'cache', $data, $expire = CACHE_PERMANENT, $headers = NULL)
6
cache_set($cid, $data, $table = 'cache', $expire = CACHE_PERMANENT, $headers = NULL)
7
cache_set($cid, $data, $bin = 'cache', $expire = CACHE_PERMANENT, array $headers = NULL)

Store data in the persistent cache.

Parameters

$cid The cache ID of the data to store.

$data The data to store in the cache. Complex data types must be serialized first.

$expire One of the following values:

  • CACHE_PERMANENT: Indicates that the item should never be removed unless explicitly told to using cache_clear_all() with a cache ID.
  • CACHE_TEMPORARY: Indicates that the item should be removed at the next general cache wipe.
  • A Unix timestamp: Indicates that the item should be kept at least until the given time, after which it behaves like CACHE_TEMPORARY.

$headers A string containing HTTP header information for cached pages.

▾ 6 functions call cache_set()

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_refresh_cache in modules/locale.module
Refreshes database stored cache of translations.
menu_get_menu in includes/menu.inc
Return the menu data structure.
page_set_cache in includes/common.inc
Store the current page in the cache.
variable_init in includes/bootstrap.inc
Load the persistent variable table.

Code

includes/bootstrap.inc, line 375

<?php
function cache_set($cid, $data, $expire = CACHE_PERMANENT, $headers = NULL) {
  db_lock_table('cache');
  db_query("UPDATE {cache} SET data = %b, created = %d, expire = %d, headers = '%s' WHERE cid = '%s'", $data, time(), $expire, $headers, $cid);
  if (!db_affected_rows()) {
    @db_query("INSERT INTO {cache} (cid, data, created, expire, headers) VALUES ('%s', %b, %d, %d, '%s')", $cid, $data, time(), $expire, $headers);
  }
  db_unlock_tables();
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.