Last updated August 24, 2016. Created on December 22, 2005.
Edited by volkswagenchick, dxx, ashish_nirmohi, harings_rob. Log in to edit this page.

To create a page Drupal needs to make several database queries. This can slow down websites with a lot of traffic. To make websites faster Drupal stores web pages in a cache.

It is a good practice to clear or rebuild caches when moving a site from one host to another. Clearing the caches can also be useful when installing new modules or themes, and as a first step in troubleshooting. During development it is necessary to clear the cache very frequently.

Clearing caches is relatively harmless. Sites might slow down for a bit afterwards while the cache fills back up.

Note that there are sometimes caches other than the Drupal cache that can affect website performance. For example, some hosting services use a cache called "Varnish" to improve performance. Also, individual web browsers maintain their own caches on a user's computer or device.

The procedure below is for clearing Drupal's internal cache. To clear a non-Drupal cache, please refer to the procedures for those caches.

About clearing the theme cache.

Clearing the cache

  1. The easiest way to clear the Drupal cache is to go to Administration > Configuration > Development > Performance (
  2. Click the button "Clear all caches"

Other ways of clearing the cache


The most convenient way to rebuild Drupal's cache is by using Drush.

Drupal 8:

drush cache-rebuild

Drupal 7 and earlier:
drush cache-clear all or alternately,

drush cc all

Run update.php

Running update.php ( is another way of clearing the cache. If you cannot login or have no user 1 rights you will need to set $update_free_access = TRUE; first in /sites/default/settings.php. Do not forget to set this back to FALSE afterwards.

A PHP snippet

Use the following code to clear specific cache type from within a module. If you want to clear all the caches similar to the functionality of the button on the "Performance" page, call this snippet for all tables beginning with the word "cache".

db_query("DELETE FROM {cache};");

In the database

Use phpMyAdmin or another tool to access the database tables and TRUNCATE (empty, not remove) all tables that start with cache_.

In phpMyAdmin, if you like to clear the whole cache_* table, select it and choose "Truncate" from the "with selected" drop-down menu at the bottom of the page. For the command line, see here:

Drupal 8 - MySQL Snippet :

TRUNCATE cache_config;
TRUNCATE cache_container;
TRUNCATE cache_data;
TRUNCATE cache_default;
TRUNCATE cache_discovery;
TRUNCATE cache_dynamic_page_cache;
TRUNCATE cache_entity;
TRUNCATE cache_menu;
TRUNCATE cache_render;
TRUNCATE cache_toolbar;

Devel module

The module Devel makes it easy to clear Drupal's cache. Just install this module and enable the "Developer/Development Block" for easy access to cache clearing. Note that "Devel" is a module designed to make development easier and should generally not be enabled on a production site.

Admin_menu module

The Administration menu (admin_menu) module has several cache clearing options for menu, page requisites, theme registry, cache tables and administration menu. It also has cron and update.php links too.

A PHP file to clear caches and rebuild the routing tables

Be careful not to leave this on the server as anyone can clear caches if they know the file name. Create a file named clear.php with the code below. Place the file in the Drupal base directory and run it by browsing to

Drupal 6

include_once './includes/';

Drupal 7 version

// Define static var.
define('DRUPAL_ROOT', getcwd());
// Include bootstrap.
// Initialize stuff.
// Clear cache.

Clearing specific entries in cache tables<>

The Drupal cache API can be used to clear specific items. Caching back ends can be switched (to memcache, to flat files, etc.) without having to rewrite any code.

cache_clear_all('content:' . $MYNID, 'cache_content', TRUE);

The example above clears all items from cache that start with 'content:$MYNID*'. To only remove one specific row, drop the $wildcard parameter (the "TRUE" statement in the function call) and change the format of the first parameter to omit the asterisk, which functions as a wildcard.

cache_clear_all('content:' . $MYNID . ':' . $MYNID, 'cache_content');

Looking for support? Visit the forums, or join #drupal-support in IRC.


kopeboy’s picture

If I am not wrong, this is clearing the caches, not rebuilding them.

How about programmatically generating the caches (let's say for a page or a View output)?!

If I have a community page and I want to show "Latest activity", cache it for 1 hour, then clear & regenerate the cache, how should I do?

Why I want to generate it before someone visits the page?
Because there will be so many things on that page to load for the poor man visiting first that he will leave my site.
This is critical for a new portal that has to gain new users..

Thanks!’s picture

Hello Kopeboy,

It's probably too late, but I think this module can help you :


ehsankhfr’s picture

You can always use another option, CTools cache.

Check ctools_object_cache functions.

grayhair’s picture

For me helped
truncate table queue

Drupal8 rc1

Situation: After broken install of modules no Frontend/Backend shown

Tryed (not solved the problem)
- truncated the cache tables
- set the $settings['update_free_access'] = TRUE;

kgun’s picture

During installation you may get this warning:

PHP OPcode caching Not enabled

PHP OPcode caching can improve your site's performance considerably. It is highly recommended to have OPcache installed on your server.

alex awg 2015’s picture

Rebuilds all Drupal caches even when Drupal itself does not work.!rebuild.php/8

hyipscript’s picture

I would say that Running update.php is not a good way of clearing the cache. My site got this error on installing Zircon 8 on Linux once the update is completed:

The website encountered an unexpected error. Please try again later


jyoti.singh’s picture

I have created a custom block in my module that displays the latest embeded tweets with given hashtags.This is achieved by using a twitter api library for configuration along with api: block displays the latest "embedded Tweets" without caching for administrator but keeps the tweets cache for anonymous users unless forcefully cache is cleared.I have also checked permissions for the block.can anyone please suggest what can be done

cpa2client’s picture

Hi All

Need help creating a clear Class Registry cache cron. I use Owl Carousel and this Class Registry seems to muck things up with combined with Boost.