Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell OkHttpClient to ignore cache and force refresh from server?

In my android application, I am using Retrofit with OkHttpClient with caching enabled to access some APIs. Some of our APIs sometimes return empty data. We provide a "Refresh" button in the app for the client to reload data from a specific API.

How do I tell OkHttpClient that a specific request should ignore the cached entry. Alternatively, is there a mechanism to delete the cached response corresponding to a single request?

I see Cache.remove(request) method but it is marked as private.

like image 252
inder Avatar asked Mar 14 '15 19:03

inder


1 Answers

As Jake Wharton suggested in issues, do this to ignore the cache:

request.setCacheControl(CacheControl.FORCE_NETWORK); 
like image 183
inder Avatar answered Oct 07 '22 22:10

inder