Caching urls with Bottlenose python Amazon product advertising API

Question:

i would like to find a way to use the cache function with bottlenose, i found somewhere that i can do it with this code but unfortunately i don’t know what to import to work with the cache :

def reader(cache_url):
return cache.ram(cache_url,lambda: None,time_expire=86400) #Time expire can be any value you want (3600 = 1hour)

def writer(cache_url, response_text):
cache.ram(cache_url,lambda: response_text,time_expire=0) #Time Expire always 0 here

can you help me ?

Thanks

Asked By: ilmetu

||

Answers:

so … i found an answer :

since i don’t know what is this cache.ram (i think its Web2py) i can surely use Redis. Redis is a nosql in ram so i can cache the url and it’s xml answer and set to expire in the next 24 hours …

def reader(cache_url,country,log):
return redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=database).get(cache_url)

def writer(cache_url, response_text,country,log):
    redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT, db=database).set(cache_url,response_text,ex=21600)

Easy.

Answered By: ilmetu