26

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?

21

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.

  • this is only the theme registry though. – Andrew Welch Dec 29 '16 at 9:56
  • 1
    The question is "How to turn it off completely?" this is only one part of it – SeanJA Mar 17 '17 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';
}
  • 4
    You can use the same trick to turn off caching per bin. Eg. $conf['cache_class_cache_metatag'] = 'DrupalFakeCache'; – Alfred Armstrong Apr 13 '15 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 Aug 6 '15 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.

  • Agreed, once you realize that most new hooks need a cache clear before being recognized its smooth sailing from there on out! :) – Alex Weber Apr 15 '12 at 4:24
  • 2
    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 Aug 6 '15 at 1:57
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
bash -c 'while [ 0 ]; do drush cc all;sleep 5;done'

which runs drush cc all every 5 seconds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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