I'm try to do Android offline caching method using OkHttp. The flow is like this:
if-none-catched
to the server, and the server returns a proper ETag. My issue now is how can I store and retrieve the ETag? Does OkHttp default will handle or I need store at SQLite? I keep looking on Google about OkHttp implement ETag sample code but all I get is just normal caching method. Link I refer:
so far what I achieved is only cache for 1st time service call, but never get latest data from server anymore. Appreciate if anyone can provide some guidance or found any good example of handle ETag and if-none-catch
dynamically for OkHttp to share with. Any clarification feel free to ask.
Retrofit vs. OkHttp The reason is simple: OkHttp is a pure HTTP/SPDY client responsible for any low-level network operation, caching, request and response manipulation, and many more. In contrast, Retrofit is a high-level REST abstraction build on top of OkHttp.
An entity tag, or ETag, is a mechanism that is provided by the HTTP protocol so that a browser client or a script can make conditional REST requests for optimistic updating or optimized retrieval of entities.
Deleting the cache when it is no longer needed can be done.
Note that the cache header can be controlled dynamically in Retrofit instead with @Header("Cache-Control") String cacheControl parameter.
You just need to enable OkHttp’s response cache. It’ll use the ETag if your webserver returns one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With