Answer the question
In order to leave comments, you need to log in
How to force Retrofit to clear the received data cache?
In general, the essence of such a purchase request is fulfilled. after which the item data is cleared on the server. But at the same time, retrofit returns them along with new ones. It only helps to do cleaning in the application settings. The retrofit itself is created like this:
@Provides
@Singleton
Cache provideHttpCache(Application application) {
//create cache storage
File httpCacheDirectory = new File(application.getCacheDir(), "responses");
int cacheSize = 10 * 1024 * 1024; // 10 MiB
return new Cache(httpCacheDirectory, cacheSize);
}
@Provides
@Singleton
OkHttpClient provideOkhttpClient(Cache cache) {
return new OkHttpClient.Builder()
.cache(cache)
.addInterceptor(new AddCookiesInterceptor(mApplication))
.addInterceptor(new ReceivedCookiesInterceptor(mApplication))
.build();
}
@Provides
@Singleton
Retrofit provideRetrofit(OkHttpClient okHttpClient) {
return new Retrofit.Builder()
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(mBaseUrl)
.client(okHttpClient)
.build();
}
<uses-permission android:name="android.permission.CLEAR_APP_CACHE"/>
public static void clearCashe(Context context) {
File dir = context.getCacheDir();
if (dir!=null && dir.isDirectory()) {
String[] child = dir.list();
for (String ch : child) {
Log.w("TEST", "delete cashe="+ch);
File file = new File(dir, ch);
file.delete();
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question