How to delete or clear Drupal cache tables?

How to delete or clear Drupal cache tables?



How to delete or clean up or clear Drupal cache tables is a question that sooner or later probably every Drupal developer asks. It is easy to delete Drupal cache tables, and clearing Drupal cache can be extremely useful when migrating your website from one environment to the another one.

Why would I need to clear Drupal cache tables?

When migrating your web from, for example, your localhost to your production environment, there is no need to migrate your cache tables in addition to all your data. They can take a lot of space. Cache is only a temporary storage, and Drupal will automatically regenerate it after you move your website.

Deleting or cleaning up cache tables can be useful also when developing and testing your website.

Important note: It is important to mention that whatever you intend do with your cache tables, we are talking about deleting data from your database tables, the content and not the database tables themselves. Deleting the tables themselves on the fly will cause many problems, so do not attempt to do that.

What database tables are involved in Drupal cache?

Depending on your website and Drupal modules configuration, you can find a number of Drupal cache tables in your database.

  • cache*
  • cache_content
  • cache_filter*
  • cache_menu*
  • cache_page*
  • cache_views

You most likely have all the tables with the star at the end. Presence of the tables without the star at the end depends on your web configuration.

How can I delete Drupal cache?

There are two ways of deleting Drupal cache. One way is to manually delete the data inside the cache tables in the database. The other way is to utilize the cache delete functionality that is already provided by Drupal and let Drupal do the work.

Since Drupal is a CMS, it is a "system", it is always better to use what the system already provides than to dig into the code.

Delete Drupal cache - option 1: Devel Module

The Drupal Devel module provides functionality that can delete cached data from your system. This module can be found at the Drupal.org website at this page: http://drupal.org/project/devel.

After you unpack the module and install it into your system, you will see that it comes with four sub-modules. If you are just starting with the Devel module and want to use it just to delete cached data in your Drupal website and nothing else, then you only need to enable the Devel sub-module of the Devel module. You do not need to enable the Generator, Macro, and the Node Devel Access sub-modules. See this link for more details and a print screen:

Drupal Devel module installation Drupal devel module installation

After you install the Devel module and enable the Devel sub-module in the Administer -> Modules screen, you also need to enable the Block that is associated with the Devel module. The Empty cache functionality link is not placed in the Administer menu as one might expect, but it is accessible from Devel's own block. Go to Administer -> Blocks and enable the Devel block.

Security: You do not want everyone to be able to access your Devel module, so go to the Administer -> User Management -> Access Control screen and allow only the admin role to see this module.

In addition to restricting who can use the Devel module functionality, you also need to restrict who can access the Devel module block. Go to your Blocks -> Devel module -> configuration screen and set permission for the admin role. See this link for more details and a print screen:

Drupal Devel module security Drupal devel module security

Now you should be able to see the Empty cache link in the Devel block. If you click this link, it will delete your Drupal's cache data.

What is the direct path to the Drupal devel module Empty cache link?

In case you have troubles setting this up, you can also access the Empty cache functionality by navigating to the devel/cache/clear page or admin/devel/cache/clear page. Navigating to this page will automatically run the scripts to delete the Drupal cache.

Where exactly this is located is defined in the function devel_menu() in the devel.module file.

Are there any complications with the Drupal Devel module Empty cache functionality?

It looks like this function does not clean up all the tables that need to be cleaned up. It depends on what tables out of the ones mentioned above you have and also on how your web is set up.

In case the Empty cache link in the Devel module does not clean up your Drupal cache as you expect, you can do the residual clean up using the cache_clear_all() function. You can read more about this on the next page: Drupal cache clean up - cache_clear_all().

.

Discuss this article or this topic in our discussion forum:
(The table bellow shows a list of 8 most recent topics posted in our discussion forum. Visit our discussion forum to see more. It is possible the links below are not related to this page, but you can be certain you will find related posts in the discussion forum. You can post one yourself too.)
Email this article to a friend:
TO: 
FROM: 
2 + 6 - 3 = 
.
How can I link to this web page?

It is easy, just include the code provided below into your HTML code.

<a href="http://www.maxi-pedia.com/how+to+delete+or+clear+Drupal+cache+tables" title="www.Maxi-Pedia.com: How to delete or clear Drupal cache tables?" target="_blank">How to delete or clear Drupal cache tables?</a>
.