4.6.x bootstrap.inc cache_get($key)
4.7.x bootstrap.inc cache_get($key)
5.x cache.inc cache_get($key, $table = 'cache')
6.x cache.inc cache_get($cid, $table = 'cache')
6.x cache-install.inc cache_get($key, $table = 'cache')
7.x 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.


$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


54 calls to 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
Gets the data representing a subtree of the book hierarchy.
BootstrapGetFilenameWebTestCase::testDrupalGetFilename in modules/simpletest/tests/bootstrap.test
Test that drupal_get_filename() works correctly with a full Drupal site.
CacheClearCase::testMinimumCacheLifetime in modules/simpletest/tests/cache.test
Test minimum cache lifetime.
CacheSavingCase::checkVariable in modules/simpletest/tests/cache.test
Check or a variable is stored and restored properly.

... See full list

1 string reference to 'cache_get'
_drupal_file_scan_cache in includes/bootstrap.inc
Returns the current list of cached file system scan results.


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


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


kendsnyder’s picture

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.


cache_set($cid, $myObject);
// ...
$cache = cache_get($cid);
$myObject = $cache->data;
kendsnyder’s picture

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';

Mark Theunissen’s picture

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


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

NROTC_Webmaster’s picture

To me it looks like they just completely removed it for D8 and kept the cache only for backward compatibility. Did this get moved/rewritten to somewhere else in D8 or was it just removed?

alberto56’s picture

Here's an equivalent line in D7 and D8 (dev):

In D7 (taken from menu.module):

$cache = cache_get($cid, 'cache_menu');

And in D8, which uses cache():

$cache = cache('menu')->get($cid);



mcrittenden’s picture

Quick fix for this in D7 is to just check time() < $cache->expire before using $cache->data.

Daniel Kulbe’s picture

Also used this fix, but using REQUEST_TIME might be better reference. (defined in bootstrap.inc)

rvelhote’s picture

This is very lame but the $expire parameter, when set in a form of a Unix timestamp, is ignored if the parameter cache_lifetime set in admin/config/development/performance is not set to X minutes.

This will cause cache_get to return expired entries!

Sadly, the description for the cache_lifetime parameter is incorrect because it mentions "cached pages" so one would assume that it's applicable to whole pages and not specific cache entries.

This is not documented and should not even happen otherwise it destroys the purpose of setting an expire parameter.

DeFr’s picture

That comment is misleading: the $expire parameter is ignored with regard to cache_get function no matter what the cache_lifetime setting is, and checking it is the responsability of the caller (as mentionned in a bunch of comments above).

What happens when you set the cache_lifetime is that the creation date of the cache entry (and not it's expiration date) is checked to see if the cache entry is "fresh enough" for the current user. It doesn't change anything with regards to the expiration.