When you are deep in the development cycle, Drupal’s robust caching system can quickly become an obstacle. You make a CSS change or update a template file, refresh the browser, and find that nothing has changed. While caching is essential for production performance, it can significantly hinder your productivity during development.
In this guide, you will learn how to effectively manage and disable Drupal caches. We will cover everything from simple UI settings to advanced settings.php configurations and command-line tools like Drush. Whether you are working on Drupal 7 or modern versions, these techniques will ensure your development environment remains responsive.
Disabling Caches via the Drupal User Interface
The most accessible way to manage caching is through the Drupal administrative interface. If you are looking for a quick way to toggle settings without touching code, this is your first stop.
Navigate to Administration > Configuration > Development > Performance (in Drupal 7, this is under Site Configuration). Here, you can disable the caching of specific site elements. You can also uncheck "Aggregate and compress CSS files" and "Aggregate JavaScript files."
Keep in mind that even with these settings disabled, Drupal may still cache theme templates and the menu router. To see changes in your theme files immediately, you will often need to manually flush the caches using the "Clear all caches" button located on this same page.
Leveraging the Devel and Admin Menu Modules
For a more streamlined development experience, the Devel and Administration Menu modules are indispensable tools. They provide shortcuts that save you from navigating deep into the configuration menus.
The Devel Module
With the Devel module installed, you gain several powerful options:
- Rebuild Theme Cache: You can set the theme registry to rebuild on every page load. This is a lifesaver for front-end developers working on .tpl.php or Twig files.
- Cache Clear Block: Devel provides a dedicated block you can add to any region (like a sidebar) containing quick links to empty specific caches or reinstall modules.
Administration Menu
The Administration Menu module adds a helpful toolbar at the top of your site. It includes a Drupal icon on the far left that, when hovered over, reveals a "Flush all caches" option. This allows you to clear the cache from any page on your site with just two clicks.
Advanced Configuration in settings.php
If you want to ensure caching is disabled programmatically—preventing it from being accidentally re-enabled via the UI—you can add configuration overrides directly to your settings.php file. This is especially useful for local development environments.
Using DrupalFakeCache
For Drupal 7 environments, you can use the DrupalFakeCache class. This class is typically used during the installation process to bypass the caching system entirely. Add the following to your settings.php:
include_once(DRUPAL_ROOT . '/includes/cache.inc');
include_once(DRUPAL_ROOT . '/includes/cache-install.inc');
$conf['cache_default_class'] = 'DrupalFakeCache';
Disabling Specific Cache Layers
You can also target specific cache systems within the $conf array (or $settings in modern Drupal). Here is a comprehensive snippet to disable various optimizations:
// Disable caches and aggregations
$conf['cache'] = 0;
$conf['block_cache'] = 0;
$conf['views_skip_cache'] = TRUE;
$conf['page_compression'] = 0;
$conf['preprocess_css'] = 0;
$conf['preprocess_js'] = 0;
Note: While disabling these makes development easier, your local site will feel slower because Drupal has to rebuild every element on every request. This is a trade-off for seeing your changes instantly.
Command Line Efficiency with Drush
If you prefer working in the terminal, Drush (the Drupal Shell) is the fastest way to handle cache management. Instead of clicking through the UI, you can run a single command to reset the site's state.
To clear all caches in Drupal 7, use:
drush cc all
For Drupal 8 and 10+, the command has evolved to "cache rebuild":
drush cr
If you find yourself needing to clear the cache frequently, you can even use a shell script to automate the process, including the manual deletion of cache tables in the database if necessary:
#!/bin/bash
# Clear Drupal cache tables via SQL and Drush
echo "SHOW TABLES LIKE 'cache%'" | $(drush sql-connect) | tail -n +2 | xargs -L1 -I% echo "DELETE FROM %;" | $(drush sql-connect) -v
drush eval 'menu_rebuild();'
echo "Cache tables cleared."
Managing External Caches (Varnish, Memcached, and OpCache)
In complex development environments, disabling Drupal's internal cache might not be enough. If your stack includes external caching layers like Varnish or Memcached, you need to address those specifically.
PHP OpCache and Accelerators
Modern PHP versions use OpCache to store precompiled script bytecode. If your code changes aren't reflecting, you might need to reset the PHP cache using Drush:
drush eval "function_exists('opcache_reset') && opcache_reset();"
Memcached and Varnish
If you use Memcached, you can flush it from the command line:
echo flush_all | nc localhost 11211
For Varnish, it is best to install the Varnish module and integrate it with your settings.php. This ensures that when you clear the Drupal cache, Varnish is purged simultaneously:
$conf['cache_backends'][] = 'sites/all/modules/contrib/varnish/varnish.cache.inc';
Frequently Asked Questions
Do any Drupal modules require caching to function?
Generally, no modules require caching to function correctly. Caching is a performance optimization, not a functional requirement. However, without it, your site will consume more server resources and load significantly slower.
Why aren't my CSS changes showing even after clearing the cache?
Check if you have CSS aggregation enabled. If you are using Internet Explorer, be aware that IE has a limit on the number of stylesheets it can load. If you disable CSS aggregation, you might exceed this limit, causing the site to appear broken. In this case, keep aggregation on but flush the cache after every change.
Will disabling cache affect my production site?
If you make these changes in settings.php, ensure you are using a conditional block (like checking for a local environment variable) so these settings do not get deployed to your production server, where caching is vital for stability.
Wrapping Up
Managing the Drupal cache is a balance between speed and visibility. For most developers, a combination of the Devel module for theme rebuilding and Drush for quick flushes provides the most efficient workflow. By utilizing settings.php overrides for your local environment, you can stop fighting the cache and start focusing on your code. Always remember to verify your version context, as commands like drush cc all have transitioned to drush cr in modern Drupal releases.