Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

Clever Caching. Instead of invalidating your cache directly, bump a version number on your model (blog entry or whatever) and use that as part of the cache key. This also gives you dynamic etags for free.

Tagged , , ,

4 comments

  1. One thing I didn't make clear in that article is that you aren't limited to a simple version number.

    You can throw whatever else you need into the same key, whether it's 'user_logged_in?', a country code, a theme setting, anything. Then any users who have the same key, will automatically get a cache hit, while those that don't will see the correct content.

    If you wanted to take it to an extreme you could even stick the user id into your cache key. While it's likely memcache will throw out a lot of still current data, you'll still get per user etags for free.

    Koz - 5th July 2007 03:09 - #

  2. Gah, how I wish Django could incorporate event based caching. Care to port Michael's code to Python, anyone?

    Henrik Lied - 5th July 2007 17:08 - #

  3. Your OpenID authentication framework is broken, by the way.

    Henrik Lied - 5th July 2007 17:16 - #

  4. Seems to work again. Sweet. :)

    Henrik Lied - 5th July 2007 17:46 - #

Sign in with OpenID

Auto-HTML: Line breaks are preserved; URLs will be converted in to links.

Manual XHTML: Enter your own, valid XHTML. Allowed tags are a, p, blockquote, ul, ol, li, dl, dt, dd, em, strong, dfn, code, q, samp, kbd, var, cite, abbr, acronym, sub, sup, br, pre

A django site