Community Documentation

cache_get

5 cache.inc cache_get($key, $table = 'cache')
6 cache-install.inc cache_get($key, $table = 'cache')
6 cache.inc cache_get($cid, $table = 'cache')
7 cache.inc cache_get($cid, $bin = 'cache')

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

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

Return value

The cache or FALSE on failure.

See also

cache_set()

▾ 46 functions call cache_get()

archiver_get_info in includes/common.inc
Retrieves 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.
CacheSavingCase::checkVariable in modules/simpletest/tests/cache.test
Check or a variable is stored and restored properly.
CacheSavingCase::testNoEmptyCids in modules/simpletest/tests/cache.test
Test no empty cids are written in cache table.
CacheSavingCase::testObject in modules/simpletest/tests/cache.test
Test the saving and restoring of an object.
CacheTestCase::assertCacheRemoved in modules/simpletest/tests/cache.test
Assert or a cache entry has been removed.
CacheTestCase::checkCacheExists in modules/simpletest/tests/cache.test
Check whether or not a cache entry exists.
check_markup in modules/filter/filter.module
Run all the enabled filters on a piece of text.
DrupalCacheArray::set in includes/bootstrap.inc
Writes a value to the persistent cache immediately.
DrupalCacheArray::__construct in includes/bootstrap.inc
Constructs a DrupalCacheArray object.
drupal_get_complete_schema in includes/bootstrap.inc
Gets the whole database schema.
drupal_lookup_path in includes/path.inc
Given an alias, return its Drupal system URL if one exists. Given a Drupal system URL return one of its aliases if such a one exists. Otherwise, return FALSE.
drupal_page_get_cache in includes/bootstrap.inc
Retrieves the current page from the cache.
drupal_render_cache_get in includes/common.inc
Gets the rendered output of a renderable element from the cache.
entity_get_info in includes/common.inc
Get the entity info array of an entity type.
FieldAttachOtherTestCase::testFieldAttachCache in modules/field/tests/field.test
Test field cache.
filter_formats in modules/filter/filter.module
Retrieve a list of text formats, ordered by weight.
filter_list_format in modules/filter/filter.module
Retrieve a list of filters for a given text format.
form_get_cache in includes/form.inc
Fetch a form from cache.
HookBootExitTestCase::testHookBootExit in modules/simpletest/tests/bootstrap.test
Test calling of hook_boot() and hook_exit().
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.
locale in modules/locale/locale.module
Provides interface translation services.
menu_get_item in includes/menu.inc
Get a router item.
menu_load_all in modules/menu/menu.module
Load all custom menu data.
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.
ModuleUnitTest::testModuleImplements in modules/simpletest/tests/module.test
Test module_implements() caching.
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.
PathTestCase::testPathCache in modules/path/path.test
Test the path cache.
simpletest_test_get_all in modules/simpletest/simpletest.module
Get a list of all of the tests provided by the system.
system_list in includes/module.inc
Build a list of bootstrap modules and enabled modules and themes.
ThemeRegistry::set in includes/theme.inc
Writes a value to the persistent cache immediately.
ThemeRegistry::__construct in includes/theme.inc
Constructs a DrupalCacheArray object.
ThemeRegistryTestCase::testRaceCondition in modules/simpletest/tests/theme.test
Tests the behavior of the theme registry class.
variable_initialize in includes/bootstrap.inc
Loads 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
Collates all information on existing fields and instances.
_field_info_collate_types in modules/field/field.info.inc
Collates all information on field types, widget types and related structures.
_menu_build_tree in includes/menu.inc
Build a menu tree.
_node_types_build in modules/node/node.module
Builds and returns the list of available node types.
_registry_check_code in includes/bootstrap.inc
Checks for a resource in the registry.
_registry_update in includes/registry.inc
Does the work for registry_update().
_theme_build_registry in includes/theme.inc
Build the theme registry cache.
_theme_load_registry in includes/theme.inc
Get the theme_registry cache; if it doesn't exist, build it.

File

includes/cache.inc, line 55
Functions and interfaces for cache handling.

Code

<?php
function cache_get($cid, $bin = 'cache') {
  return _cache_get_object($bin)->get($cid);
}
?>

Comments

Return Value

The return value is an object representing the row in the cache table. To get the actual value out, access the data property. The data property is already unserialized.

Example:

<?php
cache_set
($cid, $myObject);
// ...
$cache = cache_get($cid);
$myObject = $cache->data;
?>

$cid Convention

Note that $cid is a string. The convention seems to be to use colons to create a sort of namespacing. So your module may want to do something like $cid = 'mymodule:mything:50';

This function will return

This function will return expired items in Drupal 7, here is the core issue for fixing in D8:

http://drupal.org/node/534092

This is not obvious from these API docs which is why I'm adding this note here.

Login or register to post comments