We've hit this scenario several times over the past year on different queries - typically slow queries (5-10 seconds) on frequently accessed web pages. We usually cache these for 6 hours or longer.<br><br>We handle this with a probabilistic timeout implemented in our application. We store a timestamp and expiration time serialized as part of the value set to memcache. The last minute or so before the key expires we randomly run the query and set the value to memcache with a new expiry. The probability ramps up from 0% to 100% over the last minute or so.
<br><br>In two places we use a different algorithm. We set no expiry on the value, but on every get we have a 1 in N chance of refreshing the value. We tune N so that the value gets refreshed approximately once every 5 minutes. Annoying part about this is as our traffic grows we have to change N to keep the expected interval constant.
<br><br>Chris<br><br>-- <br><a href="http://avatars.imvu.com/chris">http://avatars.imvu.com/chris</a>