volley设置缓存过期后重新请求缓存

来源:互联网 发布:陕西省大数据集团 录取 编辑:程序博客网 时间:2024/06/05 04:48

volley的使用这里我就不说了,只需要在初始化StringRequest之前执行以下代码即可

if (queue.getCache().get(url) != null) {    Cache.Entry entry = queue.getCache().get(url);    entry.softTtl = entry.serverDate + 1800000; //这里使用了缓存新鲜度来保存从服务器获取数据的时间加上半个小时(即半个小时过期)    //refreshNeeded():判断是否需要刷新网络    if (!entry.refreshNeeded()) {    String data = new String(queue.getCache().get(url).data);    LogUtil.logD("缓存URL:" + url + "\n--DATA:" + data);    }    LogUtil.logD("超过了半个小时"); }

荆轲刺秦王

原创粉丝点击