If I needed to cache something for "offline" mode ...
# squarelibraries
c
If I needed to cache something for "offline" mode for an api that doesn't send back any caching headers. Would you: 1. Write an interceptor that adds some sort of basic cache header so that even without a network connection the http client still returns data I can display on the screen 2. Just save my json response as a file and read from that if I'm "offline" Note: I know "offline" is not really a true state, but in my case my PM just wants data to show when the user is actually in airplane mode.
k
I've done (1) for 10min to buffer against temp network glitches but better if you write it to a proper DB...
c
So just a max-age header thats like 10 minutes ahead?
e
how reliable do you need it to be?
even with cache headers, you can't assume that something will stay in HTTP cache - maybe it's evicted for space
if you must have something available in offline, then it won't be sufficient, but if you just want something which won't need to be retrieved from network again when moving between screens, then maybe http cache is ok
although for $WORK app, we don't use http caching and rely on our own caching system, which has features like compression on disk and a small in-memory cache of parsed objects so they don't need to be re-parsed
c
interesting points about the http cache being finite. i know you can set how much space the okhttp cache has so I thought I'd just ramp that up.