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.

The persistent cache is split up into several cache bins. In the default cache implementation, each cache bin corresponds to a database table by the same name. Other implementations might want to store several bins in data structures that get flushed together. While it is not a problem for most cache bins if the entries in them are flushed before their expire time, some might break functionality or are extremely expensive to recalculate. These will be marked with a (*). The other bins expired automatically by core. Contributed modules can add additional bins and get them expired automatically by implementing hook_flush_caches().

  • cache: Generic cache storage bin (used for variables, theme registry,

locale date, list of simpletest tests etc).

  • cache_block: Stores the content of various blocks.
  • cache field: Stores the field data belonging to a given object.
  • cache_filter: Stores filtered pieces of content.
  • cache_form(*): Stores multistep forms. Flushing this bin means that some

forms displayed to users lose their state and the data already submitted to them.

  • cache_menu: Stores the structure of visible navigation menus per page.
  • cache_page: Stores generated pages for anonymous users. It is flushed

very often, whenever a page changes, at least for every ode and comment submission. This is the only bin affected by the page cache setting on the administrator panel.

  • cache path: Stores the system paths that have an alias.
  • cache update(*): Stores available releases. The update server (for

example, drupal.org) needs to produce the relevant XML for every project installed on the current site. As this is different for (almost) every site, it's very expensive to recalculate for the update server.

The reasons for having several bins are as follows:

  • smaller bins mean smaller database tables and allow for faster selects and inserts
  • we try to put fast changing cache items and rather static ones into different bins. The effect is that only the fast changing bins will need a lot of writes to disk. The more static bins will also be better cacheable with MySQL's query cache.

Parameters

$cid The cache ID of the data to store.

$data The data to store in the cache. Complex data types will be automatically serialized before insertion. Strings will be stored as plain text and not serialized.

$bin The cache bin to store the data in. Valid core values are 'cache_block', 'cache_field', 'cache_filter', 'cache_form', 'cache_menu', 'cache_page', 'cache_path', 'cache_registry', 'cache_update' or 'cache' for the default cache.

$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.

▾ 27 functions call cache_set()

archiver_get_info in includes/common.inc
Retrieve a list of all available archivers.
book_menu_subtree_data in modules/book/book.module
Get the data representing a subtree of the book hierarchy.
check_markup in modules/filter/filter.module
Run all the enabled filters on a piece of text.
drupal_cache_system_paths in includes/path.inc
Cache system paths for a page.
drupal_get_schema in includes/bootstrap.inc
Get the schema definition of a table, or the whole database schema.
drupal_page_set_cache in includes/common.inc
Store the current page in the cache.
drupal_render_cache_set in includes/common.inc
Cache the rendered output of a renderable element.
entity_get_info in includes/common.inc
Get the entity info array of an entity type.
field_attach_load in modules/field/field.attach.inc
Load all fields for the most current version of each of a set of objects of a single object type.
form_set_cache in includes/form.inc
Store a form in the cache.
image_effect_definitions in modules/image/image.module
Pull in image effects exposed by modules implementing hook_image_effect_info().
image_styles in modules/image/image.module
Get an array of all styles and their settings.
image_style_url in modules/image/image.module
Return the URL for an image derivative given a style and image path.
locale in modules/locale/locale.module
Provides interface translation services.
menu_tree_all_data in includes/menu.inc
Get the data structure representing a named menu tree.
menu_tree_page_data in includes/menu.inc
Get the data structure representing a named menu tree, based on the current page.
module_hook_info in includes/module.inc
Retrieve a list of what hooks are explicitly declared.
module_implements in includes/module.inc
Determine which modules are implementing a hook.
module_implements_write_cache in includes/module.inc
Writes the hook implementation cache.
simpletest_test_get_all in modules/simpletest/simpletest.module
Get a list of all of the tests provided by the system.
variable_initialize in includes/bootstrap.inc
Load the persistent variable table.
_block_render_blocks in modules/block/block.module
Render the content and subject for a set of blocks.
_field_info_collate_fields in modules/field/field.info.inc
Collate all information on existing fields and instances.
_field_info_collate_types in modules/field/field.info.inc
Collate all information on field types, widget types and related structures.
_registry_check_code in includes/bootstrap.inc
Helper to check for a resource in the registry.
_registry_rebuild in includes/registry.inc
@see registry_rebuild.
_theme_save_registry in includes/theme.inc
Write the theme_registry cache into the database.

Code

includes/cache.inc, line 133

<?php
function cache_set($cid, $data, $bin = 'cache', $expire = CACHE_PERMANENT, array $headers = NULL) {
  return _cache_get_object($bin)->set($cid, $data, $expire, $headers);
}
?>
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.