目前我试图为我的球衣宁静服务启用缓存.
所以出现了一些问题.
什么是entityTag的价值?它可以只是一个独特的生成随机字符串吗?
当我从客户端向服务器发出请求时,我会使用实体标记返回响应.问题:如何缓存此问题以及如何知道我必须为下一个获取请求发送哪个缓存的entityTag?
在服务器端,我得到了发送的entityTag.我如何将其与资源进行比较?因为我没有将entityTag附加到资源.
它只是比较entityTags.那么我什么时候需要最后修改的标头值?
对不起,很高兴得到一个服务器和客户端的例子.我找不到这个问题.如何在请求中发送entityTags,如何在服务器端比较它们以及最后修改的内容.
ETag为客户端缓存提供了一种机制,以验证缓存的内容是否仍然是最新的.关于你的问题:
在服务器端,Jersey支持评估ETag并生成响应.例如,您的资源方法可能如下所示:
@GET
public Response doGet() {
EntityTag et = yourMethodForCalculatingEntityTagForThisResource();
// the following method call will result in Jersey checking the headers of the
// incoming request, comparing them with the entity tag generated for
// the current version of the resource generates "304 Not Modified" response
// if the same. Otherwise returns null.
ResponseBuilder rb = request.evaluatePreconditions(new EntityTag("1"));
if (rb != null) {
// Jersey generated 304 response - return it
return rb.build();
}
// return the current version of the resource with the corresponding tag
return Response.ok(getCurrentVersion(), "text/plain").tag(et).build();
}
Run Code Online (Sandbox Code Playgroud)
为最后修改的标题以及etag和last-modified提供了相同类型的支持.
这篇维基百科文章提供了ETag的一个很好的概述:http://en.wikipedia.org/wiki/HTTP_ETag
| 归档时间: |
|
| 查看次数: |
3053 次 |
| 最近记录: |