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.
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 - #
Is it true that a single write to a tables invalidate all the reads involve with this table?
pablo - 1st March 2010 16:07 - #
@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 - #
Never seen a bteter post! ICOCBW
Laticia - 3rd July 2011 00:12 - #
Alex Work - 28th October 2011 02:35 - #
ugg pas cher - 28th October 2011 03:39 - #