简体   繁体   English

如何使httplib2缓存为只读?

[英]How to make httplib2 cache readonly?

The following code creates Http object with caching enabled: 以下代码创建启用了缓存的Http对象:

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对象,如果资源已经在缓存中,则不再请求它:

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? 如何修改这两个样本以用于已使用但从未更新的cache

Thanks 谢谢

You can pass a cache into the Http object you construct, if it implements these methods : 如果实现以下方法 ,则可以将缓存传递到构造的Http对象中:

 Cache.get(key) Cache.set(key, value) Cache.delete(key) 

Wrap an instance of FileCache with an object that you retain a reference to. 用您保留引用的对象包装FileCache的实例。 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). 在您的初始请求之后,请更改其行为,以使get继续起作用, set委托setdelete (这样就永远不会返回陈旧的值)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM