Open wzasd opened 7 years ago
没看太懂,你说的是缓存机制在哪里无法使用?
static Interceptor REWRITE_CACHE_CONTROL_INTERCEPTOR = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
CacheControl.Builder cacheBuilder = new CacheControl.Builder();
cacheBuilder.maxAge(60, TimeUnit.SECONDS);
cacheBuilder.maxStale(365,TimeUnit.DAYS);
CacheControl cacheControl = cacheBuilder.build();
Request request = chain.request();
request = request.newBuilder()
.cacheControl(cacheControl)
.build();
Response originalResponse = chain.proceed(request);
int maxAge = 60; // read from cache
return originalResponse.newBuilder()
.removeHeader("Pragma")
.header("Cache-Control", "public ,max-age=" + maxAge)
.build();
}
};
就是自己写的使用okhttp3.0的缓存机制,有木有推荐的缓存办法呢?
我尝试使用okhttp3自带的缓存机制为什么无法使用呢?您使用过自带的缓存机制吗?望回复