如何删除HTTP缓存当用户在使用MVP / Dagger和Repository Pattern时注销

问题描述 投票:0回答:1

我正在使用OKHTTP和Retrofit处理网络调用,我不知道如何在用户注销时清除缓存,我在项目中使用MVP / Repository模式和dagger

这是我称之为https://github.com/LadwaAditya/DaggerRetrofitOkhttp-Tutorial的示例项目

OkHttpClient tempClient = new OkHttpClient.Builder()
                    .readTimeout(60, TimeUnit.SECONDS)// connect timeout
                    .connectTimeout(60, TimeUnit.SECONDS)// socket timeout
                    .followRedirects(false)
                    .cache(provideHttpCache())
                    .addNetworkInterceptor(new ResponseCacheInterceptor())
                    .addInterceptor(new AddHeaderAndCookieInterceptor())
                    .build();

  private  Cache provideHttpCache() {
        Cache cache = new Cache(new File(Application.getAppInstance().getCacheDir(), CACHE_DIR_NAME), CACHE_SIZE);
        return cache;
    }

OKHTTP有一个Cache.evict方法,但我不确定如何公开这个方法

android retrofit retrofit2 okhttp3
1个回答
0
投票

您是否尝试在注销时调用Cache中的OkHttpClient并调用tempClient.cache().delete()delete()evictAll()似乎都是从文档中公开的。

© www.soinside.com 2019 - 2024. All rights reserved.