Skip to content

有个关于您封装的 retrofit2 网络缓存部分的问题想请教您 #1

@tosslife

Description

@tosslife

我用的retrofit2.3.0 ,
首先是 LoggingIntercepter debug模式也依旧打印不出信息。
Platform.get().log(INFO, message, null);
并未执行出结果,换成传统的Log.d("",message);可以。
再就是缓存部分cacheIntercepter
首先我的服务器不支持 cache-control
默认为
Cache-Control →private, must-revalidate
造成HTTP 504 Unsatisfiable Request (only-if-cached)异常
然后我做了更改cacheIntercepter中网络可用情况下的响应返回
res = response.newBuilder()
.removeHeader("Pragma")
.removeHeader("Cache-Control")
.header("Cache-Control", "public, max-age=" + maxAge)
.build();
通过返回新建的response来保存响应头中cache-control
但是当我关掉网络,再次打开app的时候
会出现Unable to resolve host "api.*.com": No address associated with hostname
并未从缓存中取出本地缓存的数据
可能是我理解错误,不知您写的这个缓存中间件的目的
是解决无网络(包括关闭wifi和移动网络)是读取缓存
还是wifi和移动网络开着但是无法联网的情况 读取缓存。
希望能得到您的解决办法。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions