April 16, 2007

Some Quick Notes About Caching

The caching module is designed to keep the most frequently requested pages in memory so that they can be served more quickly.  Every time you request a page, the server first checks if it already has a copy in the cache.  If it doesn't, it creates the page from the templates, and then saves a copy in the cache - possibly pushing an older page out of the way to do so.

Pages live in the cache for a limited amount of time, currently 120 seconds.  They are automatically flushed (removed from the cache) after certain events; leaving a comment on a page, for example, will flush that individual page.  And pages are never cached if you are logged in, so you will never see an old copy of a page while you are maintaining your site.

The real benefit of the cache comes in when you get a link from a high-traffic site like Slashdot, Fark, or Instapundit.  The main page of my blog currently takes around 400 milliseconds to generate (it has a lot of comments...) Once in the cache, it takes just 3.5 milliseconds - over 100x faster.  You can imagine the difference that would make to the server if I got 10,000 visitors in the space of an hour.  Typically the performance gain would be somewhat less than that, in the range of 20x to 60x, but still definitely worthwhile.

If you log out and reload a page a couple of times, you'll see that the system actually tells you that it's coming from the cache, so you can keep an eye on this yourself.

Posted by: Pixy Misa at 08:06 AM | No Comments | Add Comment
Post contains 274 words, total size 2 kb.

Comments are disabled. Post is locked.
9kb generated in CPU 0.01, elapsed 0.017 seconds.
30 queries taking 0.0102 seconds, 51 records returned.
Powered by Minx 1.1.6c-pink.