Disabling all of Drupal's Cache (D6 and D7)

Sometimes you wished that all of Drupal cache would be disabled for the sake of testing or any other purpose.

Just call the enable/disable function at will in your custom code. Dont forget to enable caching for production, if you intend to use this in your development

Drupal 7

  1. function my_module_cache_disable() {
  2. if (!class_exists('DrupalFakeCache')) {
  3. $cache_backends = variable_get('cache_backends', array());
  4. $cache_backends[] = 'includes/cache-install.inc';
  5. variable_set('cache_backends', $cache_backends);
  6. }
  7. // Default to throwing away cache data
  8. variable_set('cache_default_class','DrupalFakeCache');
  9. // Rely on the DB cache for form caching - otherwise forms fail.
  10. variable_set('cache_class_cache_form', 'DrupalDatabaseCache');
  11. }
  12.  
  13. function my_module_cache_enable() {
  14. // Default to throwing away cache data
  15. variable_del('cache_default_class');
  16. // Rely on the DB cache for form caching - otherwise forms fail.
  17. variable_del('cache_class_cache_form');
  18. }

Drupal 6

  1. function my_module_cache_disable() {
  2. variable_set('cache_inc', './includes/cache-install.inc');
  3. }
  4. function my_module_cache_enable() {
  5. variable_del('cache_inc');
  6. }