Reputation: 749
I'm trying to cache data with OKHttp's native cache; my problem is that I don't have control over the server side data, and the response header Cache-Control is coming back with a "no-cache" value.
Is there anyway to intercept the request to add in a header to cache the data that's coming back using OkHttp? (I'd also like to cache specific requests if possible).
Thank you! Best Regards, Christopher Steven
Upvotes: 0
Views: 684
Reputation: 792
Just in case anyone else comes across this 18 months late... you can now "defeat" Cache-Control: no-cache
through adding an interceptor as a network interceptor (so it updates the server response before OkHttp processes it).
There is a good example on the OkHttp wiki at https://github.com/square/okhttp/wiki/Interceptors#rewriting-responses.
Hope this helps.
Upvotes: 0
Reputation: 40593
OkHttp doesn't currently offer a mechanism to defeat Cache-Control: no-cache
. OkHttp will end up validating the response with the server, but if the server says the stored response is still good then the response body won't need to be retransmitted.
We've got a feature request outstanding that wants something like this, though it's difficult because it may mean a single request yields multiple responses.
Upvotes: 2