How to invalidate/force update of cache route at next request with Retrofit and OKHttp?-open source projects square/okhttp

I’m using Retrofit with OKHttp client for caching responses from a JSON API.

This works nicely.

However, if I take an action on the device which causes the data to update on the server I need a way to ‘invalidate’ a particular route in order to ensure that next time a request is made for this data, it is fetched from the server again rather than the now outdated cached version.

Currently, I’ve worked around this by explicitly calling the new route with a “no-cache” flag in the Cache-Control header of the request, but this forces me to download the new data before it is needed, potentially multiple times if multiple actions are taken, just to keep the cache up to date.

Is there a way I can mark a route / method in my retrofit/OKhttp client as cache expired, requiring a mandatory update over the network the next time it’s requested?