我正在使用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方法,但我不确定如何公开这个方法
您是否尝试在注销时调用Cache中的OkHttpClient
并调用tempClient.cache().delete()
? delete()
和evictAll()
似乎都是从文档中公开的。