Clear cache

Drupal code is very heavy on SQL Usage. It is not uncommon to run 5 or more SQL queries just to display a page. As you can imagine, this slows down the website significantly. In addition, this increases load on the server. To go around this problem, drupal offers the possibility to cache the pages the user has already visited. This way, there is only one database call, one simply SQL query to run, reduced load on the server, and run better response time.

New drupal developers often get frustrated by drupal's caching mechanism. You make a change but you don't see the change since the menu is coming from the cache. You think the problem is in the code, and you try to find the culpable code in vain. To avoid this agonizing situation, you need to do the following two things:

  1. disable page caching
  2. Install the clear cache module

Disabling page caching

  1. Go to Administer >> Settings
  2. Click on Cache Settings
  3. Under the Page Cache heading, select Disabled
  4. Hit Save Configurations

Installing the clear cache module

Following is a small module I created which cleans your cache and rebuilds the menus. Copy paste this code to create a clear_cache.module under the modules directory. Then go to Administer >> modules to enable this module. All you need to do to flush your cache is to click on the Flush cache link inside the navigation menu.


function clear_cache_help($section) 
  switch ($section) {
    case 'admin/modules#description':
      return t('cleans cache');

function flushcache_menu($may_cache) 
  $items = array();

  if ($may_cache) {
    $items[] = array( 'path' => 'admin/clear_cache', 
                      'title' => t('Clear cache'),
                      'callback' => 'clear_cache_page',
                      'access' => user_access('administer email aliases')); // or something else
  return $items;

function clear_cache_page(){
  db_query("DELETE FROM {cache}");
  drupal_set_title('Flush Cache');
  drupal_set_message('Cache has been flushed');
  print theme('page', '');

To clear you cache and to rebuild your menus, simply click on Administer >> clean cache.