【问题标题】:Android volley caching -How to display stale cached data when there is no network connectivity?Android volley 缓存 - 如何在没有网络连接时显示陈旧的缓存数据?
【发布时间】:2014-01-21 04:03:00
【问题描述】:

我已经根据服务器发送的标头缓存了来自服务器的响应。最大年龄的值是 180 秒。据我了解,如果在 180 秒 volley 框架将缓存替换为服务器数据的更新版本之后,是否对相同的 url 发出任何请求。 我想在不存在网络连接时显示缓存数据。我如何使用 android volley 来实现这个???

【问题讨论】:

  • 我想你已经完成了..关闭你的网络并检查你的回复
  • 我关闭了我的网络 n 检查了我的响应 ..在 180 秒之前它从缓存中获取数据并且我的响应代码是 201 ..而在 180 秒之后数据没有从缓存中获取并且调用 void onErrorResponse(VolleyError error)。
  • 可以通过 VolleyError 处理 error = (VolleyError) err;

标签: android caching android-volley


【解决方案1】:

在这种情况下,处理网络错误,当它发生时,直接使用mQueue.getCache().get(request.getCacheKey())从缓存中获取数据,即使在缓存中也会返回数据如果过期了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-20
    • 2012-03-08
    • 1970-01-01
    相关资源
    最近更新 更多