0

What i want to do is at a specific time bypass cache, make an http request and then update the new result back to cache for the next time I need it. Is there any way to do this with retrofit + okhttp in android??

  • 1
    You need to be more specific. What cache are you trying to bypass? What have you tried so far, and what's the problem exactly? – pablochan Mar 21 '17 at 09:26
  • I have created a http client like described in the following stackoverflow link: http://stackoverflow.com/questions/23429046/can-retrofit-with-okhttp-use-cache-data-when-offline . I use cached data for offline usage and for navigating inside my android app when inside max-age. What i want is give user the ability to force update the data of the app at a specific time. In that case, do make a http request to the server, get data and then update cache data for future usage. – Christos Georgiadis Mar 21 '17 at 12:55

1 Answers1

0

You can force a network request by using CacheControl.FORCE_NETWORK for the request. You could either do it when creating the request, or in an interceptor.

Another way would be to use Cache.evictAll() to clear the cache completely. Any subsequent requests will be put in the cache.

You can use a Timer to schedule and trigger the eviction process.

pablochan
  • 5,625
  • 27
  • 42