缓存听上去像是比较先进的东西,其实就是在应用程序在被杀掉之前,可以保存在内存中,这样,你就可以利用缓存来获取。我们介绍一种向服务器请求的简单缓存,可以方便的使用它来减少与服务器的交互,减轻服务器的压力
利用apache提供的向服务器的请求源码,在请求之前,取缓存内容,如果有,不交互,如果没有,则交互,将获取的内容放在缓存中,这样的一个循环的过程。
关键代码如下:
public static String doGet(String url) throws SHError {
String data = null;
// TODO: get the data from the request cache.
if (requestCache != null) {
data = requestCache.get(url);
if (data != null) {
Log.d(FiberHomeApplication.TAG, "Apache Caller.doGet [cached] " + url);
return data;
}
}
URI encodedUri = null;
HttpGet httpGet = null;
try {