The following code creates Http object with caching enabled:
http = httplib2.Http('cache')
r, b = http.request('http://google.com')
The following code creates Http object with caching enabled and if the resource has already been in the cache, its never requested again:
http = httplib2.Http('cache')
r, b = http.request('http://google.com',
headers={'cache-control':'min-fresh=-1000000000'})
How do I modify these two samples for the cache
is used but never updated?
Thanks
You can pass a cache into the Http
object you construct, if it implements these methods :
Cache.get(key) Cache.set(key, value) Cache.delete(key)
Wrap an instance of FileCache
with an object that you retain a reference to. After your initial requests, change its behaviour so that get
continues to work and set
delegates to delete
(so you never return a stale value).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.