Friday, 7 December 2012

Drupal 7 - Disable Drupal Caching

  1. Create a Custom Module in sites/all/modules.
  2. Write the below two function in CustomModule.Info file in Custom Module Folder 

/* Disable Cache of Drupal */
function mycustommodule_caching_disable() {
    if (!class_exists('DrupalFakeCache')) {
        $cache_backends = variable_get('cache_backends', array());
        $cache_backends[] = 'includes/cache-install.inc';
        variable_set('cache_backends', $cache_backends);
    }
    // Default to throwing away cache data
    variable_set('cache_default_class','DrupalFakeCache');
   
    // Rely on the DB cache for form caching - otherwise forms fail.
    variable_set('cache_class_cache_form', 'DrupalDatabaseCache');
}
/* Disable Cache of Drupal */

/* Enable Cache of Drupal */
function mycustommodule_caching_enable() {
    // Default to throwing away cache data
    variable_del('cache_default_class');
   
    // Rely on the DB cache for form caching - otherwise forms fail.
    variable_del('cache_class_cache_form');
}
/* Enable Cache of Drupal */ 

Note: Those two functions are Custom Functions not Drupal hook functions. So,
  1. If you want to disable the Caching, Call "mycustommodule_caching_disable".
  2. If you want to re enable the Caching, Call "mycustommodule_caching_enable".

No comments:

Post a Comment

Thank you so much for providing your valuable feedback. I will will look into them and update my skills & technologies accordingly.