public class CacheInterceptorOffline extends CacheInterceptor
描述:支持离线缓存,使用OKHttp自带的缓存功能
配置OKHttp的Cache
配置请求头中的cache-control或者统一处理所有请求的请求头
云端配合设置响应头或者自己写拦截器修改响应头中cache-control
列:
在Retrofit中,我们可以通过@Headers来配置,如:
@Headers("Cache-Control: public, max-age=3600)
@GET("merchants/{shopId}/icon") Observable<ShopIconEntity> getShopIcon(@Path("shopId") long shopId);
如果你不想加入公共缓存,想单独对某个api进行缓存,可用Headers来实现
请参考网址:http://www.jianshu.com/p/9c3b4ea108a7
cacheControlValue_Offline, cacheControlValue_Online, context, maxStale, maxStaleOnline| Constructor and Description |
|---|
CacheInterceptorOffline(android.content.Context context) |
CacheInterceptorOffline(android.content.Context context,
java.lang.String cacheControlValue) |
CacheInterceptorOffline(android.content.Context context,
java.lang.String cacheControlValue,
java.lang.String cacheOnlineControlValue) |
| Modifier and Type | Method and Description |
|---|---|
Response |
intercept(Chain chain) |
public CacheInterceptorOffline(android.content.Context context)
public CacheInterceptorOffline(android.content.Context context,
java.lang.String cacheControlValue)
public CacheInterceptorOffline(android.content.Context context,
java.lang.String cacheControlValue,
java.lang.String cacheOnlineControlValue)
public Response intercept(Chain chain)
throws java.io.IOException
intercept in class CacheInterceptorjava.io.IOException