Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

Johnny Cache. Clever twist on ORM-level caching for Django. Johnny Cache (great name) monkey-patches Django’s QuerySet classes and caches the result of every single SELECT query in memcached with an infinite expiry time. The cache key includes a “generation” ID for each dependent database table, and the generation is changed every single time a table is updated. For apps with infrequent writes, this strategy should work really well—but if a popular table is being updated constantly the cache will be all but useless. Impressively, the system is transaction-aware—cache entries created during a transaction are held in local memory and only pushed to memcached should the transaction complete successfully.

Tagged , , , , , , ,

6 comments

  1. Wow, I was basically writing most of this same idea today for a project. Must be something in the water.

    Caching (and invalidation) like this is so hard to get right, it would be a huge benefit to build this into Django proper someday.

    Brian Beck - 1st March 2010 00:01 - #

  2. Is it true that a single write to a tables invalidate all the reads involve with this table?

    pablo - 1st March 2010 16:07 - #

  3. @pablo

    It should, because otherwise you would have to semantically parse queries to understand wether it was affected by the write at hand. Such behaviour should be left to hand-crafted caching mechanisms.

    bastih - 1st March 2010 16:50 - #

  4. Never seen a bteter post! ICOCBW

    Laticia - 3rd July 2011 00:12 - #

  5. Work Goals Personal Development

    Alex Work - 28th October 2011 02:35 - #

  6. I will recommend my friends to read this. Bottes UGGI am quite sure they will UGG Pas Cher learn lots of new stuff here than anybody else!

    ugg pas cher - 28th October 2011 03:39 - #

Comments are closed.
A django site