使用 Bottlenose 缓存 url python 亚马逊产品广告 API
Caching urls with Bottlenose python Amazon product advertising API
我想找到一种方法来使用 bottlenose 的缓存功能,我发现某个地方可以用这段代码来实现,但不幸的是我不知道要导入什么来使用缓存:
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)
简单。
我想找到一种方法来使用 bottlenose 的缓存功能,我发现某个地方可以用这段代码来实现,但不幸的是我不知道要导入什么来使用缓存:
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)
简单。