Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

缓存的问题 #18

Open
wzasd opened this issue Jan 20, 2017 · 2 comments
Open

缓存的问题 #18

wzasd opened this issue Jan 20, 2017 · 2 comments

Comments

@wzasd
Copy link

wzasd commented Jan 20, 2017

我尝试使用okhttp3自带的缓存机制为什么无法使用呢?您使用过自带的缓存机制吗?望回复

@rengwuxian
Copy link
Owner

没看太懂,你说的是缓存机制在哪里无法使用?

@wzasd
Copy link
Author

wzasd commented Jan 22, 2017

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的缓存机制,有木有推荐的缓存办法呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants