21

是否可以修改谷歌 Volley 库中缓存的过期策略?我相信您可以实现自己的缓存,但是有没有一种简单的方法可以使用默认实现来做到这一点?

4

2 回答 2

24

无需编写自己的缓存实现。您可以更改方法 com.android.volley.toolbox.HttpHeaderParser.parseCacheHeaders(NetworkResponse response),忽略这些标头,将 entry.softTtl 和 entry.ttl 字段设置为适合您的任何值,并在您的请求类中使用您的方法。

我对类似问题的回答中有一个示例 - Android Volley + JSONObjectRequest Caching

于 2013-05-31T07:55:31.743 回答
19

It seems that currently the cache expiration is controlled solely by the "Cache" headers in the response so basically you are left to the mercy of the server. Whatever server returns in the "Expires" or "max-age=" that will be used. We will have to use our own cache if we need custom expiry policy...

于 2013-05-29T08:50:14.040 回答