实现HTTP和HTTPS请求的自动缓存:HttpResponseCache
这个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"); } }
本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!