I wan to know if there is a better way to handle “sql bursts” when using memcache.
let me explain with an example
object = memcache.get('some_key')
if object is None:
#multiple request will cause a bursts of sqls
object = Object() #this trigger some sql
memcache.set('some_key',oject,60)
so a way I found to avoid sql bursts
object = memcache.get('some_key');
if(object is None or object.expire + rand(0,120) > now())
#this not guarantees sql burst, but it will reduce them
object = Object() #this trigger some sql
object.expire = now() + 300
memcache.set('some_key',object,60)
second option don’t guarantees to avoid sql bursts and also I don’t like to add expire to my object.
There’s a few options mentioned on the memcache wiki.