[英]Caching urls with Bottlenose python Amazon product advertising API
我想找到一種方法來對瓶頸使用緩存功能,我發現可以在此代碼中完成此操作,但是不幸的是,我不知道導入什么才能使用緩存:
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
你能幫助我嗎 ?
謝謝
所以...我找到了答案:
因為我不知道這個cache.ram是什么(我認為它是Web2py),所以我肯定可以使用Redis。 Redis是ram中的nosql,因此我可以緩存url及其xml答案,並設置為在接下來的24小時內過期...
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)
簡單。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.