Hi--
One problem with caching DB queries is that, when the cache expires,
multiple requesters can cause a pileup on the DB, all trying to refill
the cache at the same time.
I've implemented some locking code for cache_fu that should prevent
pileups. I'd appreciate some feedback.
Overall, here's the idea:
When putting an item into the cache, also insert a separate cache item
that contains the item's "freshness" date, which is 80% of the cache
period. When getting an item from cache, if the item is past its
freshness date, obtain a lock for the item, then fill the cache. If
the item is still fresh, or you can't obtain a lock, just use the
existing cached data. The lock period is a little less than 10% of the
cache period. In theory this lets two requests have a whack at filling
the cache before the item expires.
The svn diff is at <
http://pastie.caboo.se/191729>. I'll do a git
thingie if anyone thinks this change is useful.
Lee