在Volley的源码中我们可以找到HttpHeaderParser这个class,里面有一段:
if(token.equals("no-cache") || token.equals("no-store")) {
return null;
}
获取头部信息判断是否是no-cache 如果是就不缓冲 我们只要重写这个方法 :
public static Cache.Entry MyparseCacheHeaders(NetworkResponse response,long cacheTime) {
Cache.Entry entry=parseCacheHeaders(response);
long now = System.currentTimeMillis();
long softExpire=now+cacheTime;
entry.softTtl = softExpire;
entry.ttl = entry.softTtl;
return entry;
}
然后在parseCacheHeaders方法中注释掉return null 就可以了;