Can't see changes to site in Drupal? Clear the Cache. (or: Everything You Wanted to Know About Caching But Were Afraid to Ask)

Jeremy John's picture

Software Developer

Blog

Can't see changes to site in Drupal? Clear the Cache. (or: Everything You Wanted to Know About Caching But Were Afraid to Ask)

share

Let's say you have a common problem in Drupal, wherein you don't see changes on your site that you've just made. Well, you've come to the right place. This post will give you an introduction to Drupal caching that will have your changes up in no time.

First option: clear your browser's cache! (Note: Dalin of Advomatic below recommends that this be the last step, for good reason. But, because its so easy, might as well do it before you go mucking around in your database or deleting files.) Your browser stores webpages so that it can, much like a lazy person, pretend like it's working, but actually be doing the browser equivalent of watching the entire season one of "The Wire" on Netflix. Here's a nice article on clearing your browser's cache.

Once you've gotten that out of the way, and your changes are not reflected, you should know that Drupal stores much of it's information in its cache. Basically, it stores rendered content in the database or in the filesystem so it doesn't have to recreate it on every page load. In order to see changes, you have to clear the cache.

Clearing the cache is harmless, no irretrievable data will be lost. One consideration for high-traffic sites is that cache clearing will put a heavier load on the server temporarily, because cached data will have to be rebuilt. But generally, cache-clearing is totally fine.

The built-in way to clear the cache is located at Administer > Site configuration > Performance, then use the Clear Cached Data button.

But the Devel module, combined with the Simplemenu module, offers a faster way to clear the cache. Enable both modules, plus the bundled Simplemenu Devel module, which will offer a dropdown in the top left corner of your site which will allow you to clear your cache.

Once devel is installed, you can clear the cache by visiting /devel/cache/clear

You can also use the Drush command to clear the cache from the cli
drush cc

The Drupal function being called is drupal_flush_all_caches(), which calls hook_flush_caches. If you have a contributed module that does not have implement a hook_flush_caches yet caches data, your module's cache will not be cleared.

Still not seeing your changes?

If I know that the settings should be reflected, or if cached data is causing my site not to load, I use phpMyAdmin to select all the tables that start with 'cache' and select "Empty". This ensures that no cached data is stored in the database.

Next, I cd into the files directory and (located at /sites/[all, default, or site_name]/files) and:

rm -rf css/* //clears the css cache
rm -rf js/* //clears the javascript cache

Still can't see your changes? Well, as they say PEBKAC

I see you like to read printed material. You should check out Nicco's book The End of Big: http://endofbig.com