以下代码创建启用了缓存的Http对象:
http = httplib2.Http('cache')
r, b = http.request('http://google.com')
以下代码创建了启用了缓存的Http对象,如果资源已经在缓存中,则它从未再次请求:
http = httplib2.Http('cache')
r, b = http.request('http://google.com',
headers={'cache-control':'min-fresh=-1000000000'})
如何使用cache
来修改这两个样本,但从未更新过?
由于
答案 0 :(得分:0)
如果它实现these methods,您可以将缓存传递给您构建的Http
对象:
Cache.get(key) Cache.set(key, value) Cache.delete(key)
使用您保留引用的对象包装FileCache
的实例。在您的初始请求之后,更改其行为,以便get
继续工作,set
委托给delete
(因此您永远不会返回过时的值)。