4.6.x bootstrap.inc cache_clear_all($cid = NULL, $wildcard = false)
4.7.x bootstrap.inc cache_clear_all($cid = NULL, $wildcard = false)
5.x cache.inc cache_clear_all($cid = NULL, $table = NULL, $wildcard = FALSE)
6.x cache.inc cache_clear_all($cid = NULL, $table = NULL, $wildcard = FALSE)
6.x cache-install.inc cache_clear_all($cid = NULL, $table = NULL, $wildcard = FALSE)
7.x cache.inc cache_clear_all($cid = NULL, $bin = NULL, $wildcard = FALSE)

Expires data from the cache.

If called with the arguments $cid and $bin set to NULL or omitted, then expirable entries will be cleared from the cache_page and cache_block bins, and the $wildcard argument is ignored.

Parameters

$cid: If set, the cache ID or an array of cache IDs. Otherwise, all cache entries that can expire are deleted. The $wildcard argument will be ignored if set to NULL.

$bin: If set, the cache bin to delete from. Mandatory argument if $cid is set.

$wildcard: If TRUE, the $cid argument must contain a string value and cache IDs starting with $cid are deleted in addition to the exact cache ID specified by $cid. If $wildcard is TRUE and $cid is '*', the entire cache is emptied.

79 calls to cache_clear_all()
2 string references to 'cache_clear_all'
menu_cache_clear in includes/menu.inc
Clears the cached data for a single named menu.
_menu_clear_page_cache in includes/menu.inc
Clears the page and block caches at most twice per page load.

File

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

Code

function cache_clear_all($cid = NULL, $bin = NULL, $wildcard = FALSE) {
  if (!isset($cid) && !isset($bin)) {
    // Clear the block cache first, so stale data will
    // not end up in the page cache.
    if (module_exists('block')) {
      cache_clear_all(NULL, 'cache_block');
    }
    cache_clear_all(NULL, 'cache_page');
    return;
  }
  return _cache_get_object($bin)->clear($cid, $wildcard);
}

Comments

MichaelCole’s picture

Elijah Lynn’s picture

In addition it is worth noting that drupal_flush_all_caches() calls cache_clear_all().

Not sure what happened to link above but this one currently works https://api.drupal.org/api/drupal/includes%21common.inc/function/drupal_...

jyee’s picture

The $bin is the name of the particular database cache table. So, for example:
cache_clear_all('field:node:' . $node->nid, 'cache_field');

W.M.’s picture

@jyee, I had to run the code you provided here after updating a particular node's field using db_update in order to reflect DB changes in node view. My question, is this the right way to do it, or should I use another method to reflect the changes after db_update? Thanks.

AlexBorsody’s picture

I built a custom module that allows the user to upload an image and then clears the cache to display the image on the page. the process takes a very long time, as the image must be uploaded then the cache cleared. right now I am using cache_clear_all but is there a way to only clear the cache for images?

		node_save($node);
		unset($node);
		$GLOBALS['conf']['cache'] = 0;
		drupal_flush_all_caches();
		cache_clear_all(NULL, 'cache_page', '*');

geerlingguy’s picture

If you'd like to clear an entire cache bin for database caches, regardless of the 'expire' value for a cached object, you need to do something like:

cache_clear_all('*', 'cache_my_module_bin', TRUE);

Providing an '*' for the first parameter tells the database cache interface's clear() method to truncate the particular cache bin.

awm’s picture

the documentation says if cid is null then "... all cache entries that can expire are deleted." what makes an entry expirable?