Drupal: How to Clear Your Cache
You may need to clear cache in the following cases:
- JS and CSS files are updated
- template.php file is updated for your current theme
- Changes in site content aren’t visible for anonymous
- Problem with access rights – you should clear cache of access rights
- Pages shown by Views module don’t reflect settings changes
Usually cache is stored in database (if you didn’t apply cache in files)
So these are the ways how you can clear cache:
Clear cache through site admin area:
Drupal 6
- Open admin/settings/performance
- Click “Clear cached data” button below
Drupal 5
If Aggregate JavaScript module is installed, then you can clear JS and CSS cache opening this address in your web-browser: http://example.com/clearjscache
Clear cache of Views module
- Open “Tools” page of Views module (admin/build/views/tools)
- Click “Clear Views cache” button (for Drupal 5)
Clear tables in database
It is better to make changes when there are not so much visitors. Or set site to “Maintenance” mode.
Clear tables with TRUNCATE operator
Run SQL-request:
TRUNCATE `cache_table_name`;
where ‘cache_table_name’ is to be replaced with a name of the appropriate cache table.
Note: this action may cause unpredictable behavior of a code for visited site. Visitors could not be not able to get site response or get an error message as this action actually recreates tables.
Clear tables with DELETE operator
This operator is executed very slowly.
DELETE FROM TABLE `cache_table_name`;
Cache tables in Drupal 6
- cache
- cache_block – blocks cache
- cache_content – content cache
- cache_filter – cache of input format
- cache_form –form cache
- cache_menu – menu cache
- cache_page – page cache
- cache_update – cache of module update status
Cache tables in Drupal 5
- cache
- cache_advcache_block –cache of advcache_block module
- cache_block – block cache
- cache_comment –comment cache
- cache_content – content cache
- cache_filter –input filter cache
- cache_forum –cache of Forum module
- cache_menu – menu cache
- cache_node – node cache
- cache_page – page cache
- cache_path – cache of URL synonyms
- cache_search – search cache
- cache_taxonomy – taxonomy cache
- cache_views –cache of Views module
- cache_workflow_ng –module cache
Clear access rights cache
Open the following page in your web-browser: admin/content/node-settings/rebuild (Drupal 6)
Clear cache with PHP-snippet
- Create a page
- Set input format to PHP
- Don’t publish the page. It haven’t to be executed:
- when applying to a node when searching,
- when cron works creating search base,
- when selecting this node to Views,
- when teaser is shown
- The page should be available for admin only
- Insert the following code to the page text:
<?php
drupal_clear_css_cache();
$core = array(‘cache’, ‘cache_content’, ‘cache_filter’, ‘cache_menu’, ‘cache_page’, ‘cache_views’);
$alltables = array_merge($core, module_invoke_all(‘devel_caches’));
foreach ($alltables as $table) {
cache_clear_all(‘*’, $table, true);
}
print(t(‘Cache cleared.’));
?>
Clear cache with the help of devel module
- Install the module
- Enable module block
- This block will contain a link to clear cache.