Effective OkHttp · omg it's mgp!
OkHttp was an invaluable library when developing the Android app for Khan Academy. While its default configuration offers significant utility, below are some steps we took for increasing the resourcefulness and introspective power of OkHttp:
1. Enable response caching on the filesystem
By default, OkHttp does not cache responses that permit caching by including such a HTTP Cache-Control
header. Therefore your client may be wasting time and bandwidth by requesting the same resource again and again, as opposed to simply reading a cached copy after the initial response.
To enable caching of responses on the filesystem, configure a com.squareup.okhttp.Cache
instance and pass it to the setCache
method of your OkHttpClient
instance. You must instantiate the Cache
with a File
representing a directory, and a maximum size in bytes. Responses that can be cached are written to the given directory. If the caching of a response causes the directory contents to exceed the given size, responses are evicted while adhering to a LRU policy.
Read full article from Effective OkHttp · omg it's mgp!
No comments:
Post a Comment