实现HTTP和HTTPS请求的自动缓存:HttpResponseCache

jopen 9年前

这个HttpResponseCache库实现了HTTP 和 HTTPS请求的透明和自动缓存,基于 java.net.HttpUrlConnection 类。

final long httpCacheSize = 10 * 1024 * 1024; // 10 MiB  final File httpCacheDir = new File(getCacheDir(), "http");  try {      Class.forName("android.net.http.HttpResponseCache")          .getMethod("install", File.class, long.class)          .invoke(null, httpCacheDir, httpCacheSize);  } catch (Exception httpResponseCacheNotAvailable) {      Ln.d(httpResponseCacheNotAvailable, "android.net.http.HttpResponseCache not available, probably because we're running on a pre-ICS version of Android. Using com.integralblue.httpresponsecache.HttpHttpResponseCache.");      try{          com.integralblue.httpresponsecache.HttpResponseCache.install(httpCacheDir, httpCacheSize);      }catch(Exception e){          Ln.e(e, "Failed to set up com.integralblue.httpresponsecache.HttpResponseCache");      }  }

项目主页:http://www.open-open.com/lib/view/home/1416292987305