Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Better options than backporting ICS HttpResponseCache

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.

like image 429
Abdullah Jibaly Avatar asked Dec 19 '11 23:12

Abdullah Jibaly


2 Answers

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.*).

like image 61
candrews Avatar answered Sep 20 '22 15:09

candrews


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.

like image 38
louielouie Avatar answered Sep 19 '22 15:09

louielouie