Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating directory for OkHttp cache on Android?

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!

like image 314
shadowmatter Avatar asked Sep 24 '15 01:09

shadowmatter


People also ask

What is OkHttp cache in android?

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.

What is OkHttp cache?

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.


1 Answers

The first one should work nicely, and gives your user a mechanism to free up disk space is necessary.

like image 179
Jesse Wilson Avatar answered Oct 18 '22 23:10

Jesse Wilson