感谢大家最近一段时间对xUtils的关注,和给我bug反馈,这也使我在xUtils的开发上更有热情。
昨天晚上熬夜到5点多,完成了缓存模块的整理和结构优化,今天在此基础上有完成了给http模块添加GET请求文本内容时实现LRU缓存的工作,现在可设置缓存默认过期时间和针对当前请求的过期时间。
GET请求缓存使用示例:
private void testGet() {
RequestParams params = new RequestParams();
params.addQueryStringParameter("method", "info");
params.addQueryStringParameter("access_token",
"3.1042851f652496c9362b1cd77d4f849b.2592000.1377530363.3590808424-248414");
HttpUtils http = new HttpUtils();
http.configCurrRequestExpiry(1000 * 10); // 设置缓存10秒,10秒内直接返回上次成功请求的结果。
http.send(HttpRequest.HttpMethod.GET,
"https://pcs.baidu.com/rest/2.0/pcs/quota",
params,
new RequestCallBack() {
@Override
public void onStart() {
testTextView.setText("conn...");
}
@Override
public void onLoading(long total, long current, boolean isUploading) {
testTextView.setText(current + "/" + total);
}
@Override
public void onSuccess(RresponseInfo responseInfo) {
testTextView.setText("response:" + responseInfo.result);
}
@Override
public void onFailure(HttpException error, String msg) {
testTextView.setText(msg);
}
});
}