I need to cache http responses, and based on this blog post that functionality is built into ICS. However, I need to support versions 1.6 and up so wanted to see if there are ready to use libraries out there before looking at what's need to backport the ICS functionality.
Update:
Here's the link to HttpResponseCache which only supports java.net.HttpURLConnection
.
Second update:
After some research, it looks like Apache's HttpClient does support caching, with the caveat that the default (in-memory) backend is probably not a good idea for memory-constrained Android apps. Ehcache may be a good option depending on its support for Android.
I created this issue requesting that a renamed, backwards compatible version of android.net.http.HttpResponseCache be added to the compatibility library: https://code.google.com/p/android/issues/detail?id=23875
Google declined the issue, but offered to help me in making the backport and library. So I'm trying to do that.
Also, HttpClient-Cache may be a neat thing to use. It doesn't work on Android as is, you need to make a small modification and recompile it. See http://comments.gmane.org/gmane.comp.apache.httpclient.user/501
However, I'd recommend you try https://code.google.com/p/httpclientandroidlib/ - it's a repackaged (renamed) version of HttpClient and HttpClient-Cache for Android. It's quite simple to set up (just include a jar and then use ch.boye.httpclientandroidlib.* instead of org.apache.http.*).
I've started using the library that candrews backported and I'm happy to report that it works well as a drop-in replacement for pre-ICS Android apps that use HttpUrlConnection. It is available at https://github.com/candrews/HttpResponseCache
Another nice thing is that it the API is the same as the ICS version, so you can enable the built-in one on ICS and use candrews' backported version pre-ICS with very little code.
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