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
Comments
12 July 2007
22 hours 32 min
I recently gave a presentation on Drupal to a group of Ruby on Rails developers who asked me if you couldn't just "turn caching off" in Drupal.
I think that the kind of caching they were referring to is page and content level caching, which can be easily disabled (mostly) via the Site Performance administration page. But unlike some other platforms, there are some cache's which are just required for Drupal to run. Examples of these are the Theme and Menu cache's. Sure, you can rebuild them every page load, but the existence of the cached objects is required for those systems to function at all, not just a matter of optimization.
cache_form is the only cache that needs to stay persistent. If you want to run with no cache add this to your settings file.
includes/cache-install.inc
Odds are this will break certain module and you will get errors like this http://drupal.org/node/795004
"First option: clear your browser's cache!"
This should actually be the final step, not the first. And if this does fix your problem it means one of two things:
1) You're doing something wrong. You did something like replacing an image with a new version. Or you have edited a CSS or JS file that is not being added to the page via drupal_add_css() or drupal_add_js(). These functions will append a random letter to the query portion of URL that changes every time the cache is cleared. You need to change the name of the file/URL because you can't expect your users to clear their browser cache every time you change a file.
2) Some module/theme/etc is doing something wrong. Unlikely but still possible. Perhaps some module somewhere is updating the contents of a static file without changing the name. If this is happening it's a bug.
14 April 2010
15 weeks 22 hours
@dalin,
Thanks for the info! I'm rolling this in to the post.
Thanks for posting Jeremy, im new to Drupal so i have had a number of issues with it over the last few days including problems in that i could not see the changes that ive made.
Looks like ive come to the right place!