【发布时间】:2013-05-22 18:52:32
【问题描述】:
public class CustomRequest extends JsonObjectRequest {
public CustomRequest(String url, JSONObject params,
Listener<JSONObject> listener, ErrorListener errorListener)
throws JSONException {
super(Method.POST,url, params, listener,
errorListener);
this.setShouldCache(Boolean.TRUE);
}
}
我希望这段代码足以让我获得响应的隐式缓存。我不确定它是否有效,因为我是在发送请求时假设的:
它会首先访问缓存并将其发送到 onresponse
然后当结果来自远程服务器时,它会将其提供给 onresponse
更新:
我想出了如何手动检索缓存并将其重建为 JSONObject 并通过 OnResponse 函数发送,但考虑到隐式缓存,这似乎效率不高。 JsonObjectRequest 类应返回 JSONObject 作为缓存条目,而不是原始响应数据。
但我仍然很想知道我是否犯了一些错误。
模棱两可完全是由于缺乏文档,所以如果我遗漏了一些非常明显的东西,我深表歉意。
【问题讨论】:
标签: android caching request response android-volley