> Hi, > > I don't know if this is a feature already - but is it possible to "pause" > memcache's expiry? > > For example we cache a lot of data in memcached (sourced from MySQL) that is > read only. If the underlying code knows the MySQL server has failed it would > be handy to "signal" memcached, and for memcached then to stop expiring > objects. > > When you signal memcached to start expiring again it should re-evaluates > objects expiry date, and set it to be "now" + whatever the expiry time was, > perhaps minus how long the object had left to live before the system was > 'paused'. > > So if you pushed an object into cache with a 5 minute expiry time, and then > signalled to memcache to "pause" expiry in 3 minutes time - that object would > not expire - instead, when you signal memcached "begin expiry" it would have > it's expiry time at that point set > to "now + 5 minutes - 3 minutes" = so now + 2 minutes. > > The reasoning behind this is: > > - In a failed MySQL environment our front line code can survive using cached > objects for a very long time if it has to, but we don't want them to expire > if we know MySQL has gone away (at the same time we don't want to set object > expiry times of hours unless we have > to). > > - We also don't want memcached to throw all the objects out the moment we > tell it to start expiring data again (to avoid the stampeding hurd). > > Is this possibel with current memcached? > > Maybe adding such a "pause" feature would be a good idea - you could have a > literal "pause" which mean no expired objects will be released from cache > (memory permitting) - but may all expire at once when the unpaused, and an > "adaptive pause" which means no expired > objects would be released, and their expiry time [upon pause removal] will be > reevaluated in accordance with the suggestion above.
It'd be a very specialized feature to do that, requiring outside coordination to all daemons, blah blah. What people usually do is another design pattern: http://code.google.com/p/memcached/wiki/NewProgrammingTricks#Avoiding_stampeding_herd see "scaling expiration" in there. In short you set item expiration to be as far as is reasonable, then use a "soft" expiration in the item. Then you can apply things like scaling random refreshes. This works better since you can adapt it very specifically to your application's particular needs.
