On Android, how should I create the File
parameter for the com.squareup.okhttp.Cache
constructor? It seems like Context
gives you plenty of options:
new File(context.getCacheDir(), "HttpResponseCache")
new File(context.getExternalCacheDir(), "HttpResponseCache")
context.getDir("HttpResponseCache", Context.MODE_PRIVATE)
Just wondering what best practice is. Thanks!
Basically: The client will send out something like timestamp or Etag of the last request. The server can then check if there is some data has changed in during that period of time or not. If nothing has changed, the server can just give a special code (304 -not modified) without sending the whole same response again.
Response caching avoids the network completely for repeat requests. OkHttp perseveres when the network is troublesome: it will silently recover from common connection problems. If your service has multiple IP addresses OkHttp will attempt alternate addresses if the first connect fails.
The first one should work nicely, and gives your user a mechanism to free up disk space is necessary.
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