iFixit / iFixitAndroid

Official iFixit Android App
https://play.google.com/store/apps/details?id=com.dozuki.ifixit
GNU General Public License v3.0
162 stars 88 forks source link

Cache API responses for offline browsing #185

Closed marczych closed 10 years ago

marczych commented 10 years ago

This adds a cache for API responses so the user can browse content offline assuming that it was previously viewed with internet available. The current implementation stores the JSON responses as files in the cache directory. This was preferable to using a database because it is faster and the storage space shows up under "Cache" rather than "App Data" so it can be cleared independently from the user's stored data.

Note: This is different than offline storage of guides because the guides and images are not stored in a permanent location.

danielbeardsley commented 10 years ago

So, this is solely so the app is kinda usable when disconnected from the net?

I think if that's the case, we should probably clear the cache the first time we connect to the net again ya? (caching is hard :( )

Also, we should probably show some indication (or just a notice that pops up on first cached GET) that we're not connected to the net or that we're using cached data.

marczych commented 10 years ago

Yes.

The cached responses won't be used at all if you do have internet so you will only see potentially stale content if you do not have internet. I don't think it makes sense to clear the cache unless it grows too large.

Yeah, I thought about displaying something to the user to indicate that the displayed data isn't live, but I wasn't sure how to do that without being obnoxious. I suppose displaying a Toast the first time a cached response is used after losing internet wouldn't be too bad. Thoughts, @timothyasp, @MutantFreak?

danielbeardsley commented 10 years ago

@marczych -- Oh, I didn't notice we store all api responses, hmm I guess there isn't another way.. never know when you're gonna lose connection. Yes, that's what I was thinking.. (the toast).

It is worth talking about the security implications (login, view private data, logout, private data still exists on phone) even though it looks like you segregate the cache by userid, the files are still there. As long as we deem that OK, it makes sense to me.

marczych commented 10 years ago

It's not all responses, only GET requests that successfully parse into our model object and have a status code of 2xx. But yes, that's practically all of them.

Only our app can access the files in the cache dir. You can, of course, root the device and have access to everything, though.

timothyasp commented 10 years ago

CR :+1: