caching - Elegant way to cache asynchronous query in Python? -


i'm using tornado web server , want take advantage of static caching asynchronous query result. python makes easy wrap function cache of sort, example using decorator:

@cache.wrap(ttl=60) def get_data(arg):     return do_query(arg) 

however, gets complex using continuation passing:

def wrap_static_result(key, result, callback, ttl):     cache.set(key, result, ttl)     callback(result)  def get_data(arg, callback):     cached = cache.get(arg)     if cached:         callback(cached)     else:         callback2 = lambda result: wrap_static_result(arg, result, callback, ttl=60)         do_async_query(arg, callback2) 

the elegant solution can think of requires making assumptions call signatures, isn't practical. can think of nicer way?

use deferreds. (the lack of such abstraction 1 of reasons tornado dramatically inferior twisted. may want check out cyclone while you're @ it.)


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -