如何避免使用凌空下载冗余数据?

时间:2018-04-04 04:26:54

标签: java android android-volley

我正在使用volley来解析json数据,而搜索我遇到了如何避免冗余数据形式的URL,volley是否具有内置函数来执行此操作,或者我们必须明确地执行以下任何帮助?

requestQueue.getCache().invalidate(url,true);
requestQueue.add(jsonObjectRequest);

1 个答案:

答案 0 :(得分:1)

请仔细阅读此主题:caching using volley 他在这里缓存数据

以下是获得回复后的一些缓存代码:

 Cache.Entry cacheEntry = HttpHeaderParser.parseCacheHeaders(response);
            if (cacheEntry == null) {
                cacheEntry = new Cache.Entry();
            }
            final long cacheHitButRefreshed = 3 * 60 * 1000; // in 3 minutes cache will be hit, but also refreshed on background
            final long cacheExpired = 24 * 60 * 60 * 1000; // in 24 hours this cache entry expires completely
            long now = System.currentTimeMillis();
            final long softExpire = now + cacheHitButRefreshed;
            final long ttl = now + cacheExpired;
            cacheEntry.data = response.data;
            cacheEntry.softTtl = softExpire;
            cacheEntry.ttl = ttl;