【问题标题】:Volley Store Each Request In App CacheVolley 将每个请求存储在应用程序缓存中
【发布时间】:2014-01-06 11:04:14
【问题描述】:
class A {
RequestQueue mRequestQueue ;
public void onCreate(Bundle saveInstance){
mRequestQueue = Volley.newRequestQueue(context);
//Reuqest Call for JsonObject
mRequestQueue.add(new JsonObjectRequest(Method.GET, _filterUri, null, new Listener<JSONObject>() {

            public void onResponse(JSONObject jObj) {
                try { // a little bit code using jObj } catch (Exception e) {
                    e.printStackTrace();
                }   
            }
        }....//and error repsone listener as well.
}

因此,我确实将 RequestQueue 与活动上下文一起保存。在 RequestQueue 命中时,总是得到一个文件,将我的调用和 jsonObject 存储在 App Cache 中,如图所示。正如我点击 RequestQueue 一样,Volley 将文件存储在缓存中。

  1. 为什么 Volley 将每个文件都存储在缓存中而不是删除?
  2. 根据 Activity 上下文调用 RequestQueue 时我做错了吗?
  3. 我使用这个 volley 缓存消耗了大量内存,是吗??
  4. 如何使用 volley 优化我的 http 调用?

【问题讨论】:

    标签: java android json caching android-volley


    【解决方案1】:
    1. 默认情况下,Volley 将根据其 HTTP 缓存标头缓存收到的每个响应。如果标头“说”缓存,Volley 缓存,否则不缓存。
    2. 我会为整个应用使用一个RequestQueue,除非您有充分的理由使用多个。
    3. 我认为 Volley 缓存默认限制为 5mb。我不确定你的意思很多,但你可以限制缓存大小。 注意,这是 Volley 使用的内部磁盘缓存,而不是您需要提供给 ImageLoader 的内存缓存。
    4. 我不确定您所说的优化 http 调用是什么意思。

    我想提醒您,Volley 是开源的,因此如果您不喜欢默认行为,可以更改它以更好地满足您的需求。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-13
      • 2010-12-29
      • 1970-01-01
      • 2018-06-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多