Skip to main content

Drupal 6.x Custom Clear all Cache Link / Page

Create a page, set the body input filter to PHP and paste the following code in the body. Add a menu link to your navigation or admin menu for easy access to clear the cache.

<?php
// only allow site administrators to visit this page:
if (!user_access('administer site configuration')) {
 
drupal_not_found();
}
else {
 
drupal_clear_css_cache();
 
$tables = array(
   
'cache',
   
'cache_content',
   
'cache_filter',
   
'cache_menu',
   
'cache_page',
   
'cache_views',
  );
  foreach (
$tables as $table) {
   
cache_clear_all('*', $table, TRUE);
  }
 
drupal_set_message('Cache cleared.');
 
drupal_goto();
}
?>

Comments

#1 Thanks, this works well - how about hook_page?

Or if you are foobar, then you can use hook_page temporarily to force a cache clear safely using Drupal functions:

<?php
   
function MYTHEME_page() {
   
drupal_clear_css_cache();
   
$tables = array(
       
'cache',
       
'cache_content',
       
'cache_filter',
       
'cache_menu',
       
'cache_page',
       
'cache_views',
    );
    foreach (
$tables as $table) {
       
cache_clear_all('*', $table, TRUE);
    }
}
?>

Remove the function after revisiting your drupal instance.