25

I am developing a site in Drupal 7 and caching slows my work significantly. For example, I had a theming function for a form. I was puzzled, why doesn't it work. Until I cleared the cache and it was fixed.

How to turn it off completely?

5 Answers 5

22

Theme functions are handled by the theme registry: rebuilding (or worse, disabling) all your site's caches to pick up a new theme function is unnecessary and overkill.

What you can do is use the Devel module to rebuild your theme's registry on every page reload. Once installed, go to Configuration → Development → Devel settings. There, check "Rebuild the theme registry on every page load" and press the "Save configuration" button. Remember to uncheck it (or better yet, disable Devel entirely) when you're done with development.

2
  • this is only the theme registry though. Commented Dec 29, 2016 at 9:56
  • 2
    The question is "How to turn it off completely?" this is only one part of it
    – SeanJA
    Commented Mar 17, 2017 at 20:30
29

You can replace the default cache backend to one which does not actually do anything. Simply add this to your settings.php file:

if (!class_exists('DrupalFakeCache')) {
  $conf['cache_backends'][] = 'includes/cache-install.inc';
}
// Default to throwing away cache data.
$conf['cache_default_class'] = 'DrupalFakeCache';
// Rely on the DB cache for form caching - otherwise forms fail.
$conf['cache_class_cache_form'] = 'DrupalDatabaseCache';

Just to be sure, set the cache expiration time to none on the Performance page.

I actually use this in a settings.local.php file which, if it exists, gets included at the bottom of my settings.php file so I can sync settings.php from the live or staging environments to my dev environment without having to worry about using the wrong database settings, accidentally pushing dev settings to live, etc.

settings.php:

if (file_exists(__DIR__ . '/settings.local.php')) {
  require_once __DIR__ . '/settings.local.php';
}
2
  • 4
    You can use the same trick to turn off caching per bin. Eg. $conf['cache_class_cache_metatag'] = 'DrupalFakeCache'; Commented Apr 13, 2015 at 10:09
  • 4
    This should be the accepted answer, as the accepted one only describes how to disable the theme registry cache and not all caches
    – mastazi
    Commented Aug 6, 2015 at 1:24
10

You can't turn of all caching completely. And if you actually did, it would slow down your progress so much more. Consider the time it takes it actually clear the cache, that's what every single page load would be like.

There are so many hooks running for building information about the available entities, fields, forms, implemented hooks etc that only need to execute once currently, you don't want to prevent that.

As you get used to Drupal, you will soon learn what things that require a cache clear, and probably get friendly with either the admin menus shortcut or drush cc all, and this will no longer be an issue.

3
  • Agreed, once you realize that most new hooks need a cache clear before being recognized its smooth sailing from there on out! :)
    – Alex Weber
    Commented Apr 15, 2012 at 4:24
  • 3
    Honestly after a few months of Drupal development I still find this to be an issue. I believe that while developing locally speed is not important, you don't have multiple users sending concurrent requests. In most other frameworks (Django, Symfony etc) having the cache disabled while developing locally is a readily available option, I don't see why I can't have that in Drupal as well. Every day I have at least one instance in which something is not working and the reason is that I forgot to clean the cache, it happens really often and it really bothers me.
    – mastazi
    Commented Aug 6, 2015 at 1:57
  • Caching is why I hate drupal. It is very badly designed compared to real frameworks like laravel. Commented Feb 19, 2023 at 12:46
1

The approach in this example is version agnostic. The code is for Drupal 7.

https://stackoverflow.com/questions/4436496/drupal-disable-css-cache/41776131#41776131

0

in drupal 10, we can do:

  1. dashboard > config > development > development setting > do not cache mark up.
  2. dashboard > config > development > performance > set caching maximum age to no caching

/admin/config/development/settings

/admin/config/development/performance

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.