凌空缓存使用的ETag [英] Volley Cache using ETag

查看:214
本文介绍了凌空缓存使用的ETag的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用乱射库,我无法正确设置缓存。

I'm using Volley library and I can't to set up caching properly.

服务器送我JSON对象,期满和ETag ..我想Voley保存这个对象在缓存中,并在此对象使用请求到服务器,包括在头ETag的下一个请求。如果响应将是304未修改,那么它应该使用缓存的资源,如果这将是200 OK,就应该从服务器使用新的资源。

Server sends me json object, expiration and ETAg.. I want to Voley save this object in cache and in next request for this object use request to the server including ETag in the header. If response will be 304 Not Modified, then it should use cached resource and if it will be 200 OK, it should use new resource from the server.

我通过看菲德勒通讯和我可以看到,排球根本不发送请求(如果缓存没有过期),或者如果它已过期发送新的请求与如果 - 无 - 匹配+ ETAG串..和服务器始终响应与200 OK

I'm watching communication via Fidler and I can see that Volley doesn't send request at all (if the cache isn't expired) or if it is expired it sends new request with If-None-Match + etag string.. and server always response with 200ok

推荐答案

我意识到,当我使用

BasicHttpClient httpClient = new BasicHttpClient();

httpClient.addHeader("If-None-Match", "vENFxg");

它总是返回200。

It always return 200.

但如果我用

httpClient.addHeader("If-None-Match", "\"vENFxg\"");

它的作品,我也得到304(HTTP_NOT_MODIFIED)。

it works, and I get 304(HTTP_NOT_MODIFIED).

您可以用下面的凌空尝试。

You can try below with volley.

@Override
public Map<String, String> getHeaders() throws AuthFailureError {
    mHeaders = new HashMap<String, String>();
    mHeaders.put("If-None-Match", "\"vENFxg\"");

    return mHeaders;
}

让我知道如果工作。

let me know if worked.

我认为你如果存放的地方凌空响应在您的应用程序,因为你需要的etag。

I assume that you store the volley response if somewhere in your app because you needed etag.

在这种情况下,我会preFER保存ETAG某处(如preferences)。
我不使用凌空一些简单的要求。

In this case, I would prefer to save the etag in somewhere(like Preferences). I do use volley with some of simple request.

排球的presentation还提到凌空完美的罚款在后台做这些同类型的操作,但它的确有过人之处在用户界面和网络的交汇点。这不是一切,虽然。

Volley's presentation also mention "volley perfectly fine for doing those same kinds of operations in the background. But it really excels at the intersection of UI and network. It's not for everything, though."

和抱歉,我的英语很差。

And sorry, my English is poor.

这篇关于凌空缓存使用的ETag的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆