Http EntityTag-值、缓存、比较-如何在Jersey中
目前,我正在尝试为我的jersey restful服务启用缓存 因此出现了一些问题Http EntityTag-值、缓存、比较-如何在Jersey中,http,rest,jersey,Http,Rest,Jersey,目前,我正在尝试为我的jersey restful服务启用缓存 因此出现了一些问题 entityTag的值是多少?它可以是唯一生成的随机字符串吗 当我从我的客户机向服务器发出post请求时,我用实体标记返回响应。问题:如何缓存这个,如何知道下一个get请求必须发送哪个缓存的entityTag 在服务器端,我得到sended entityTag。如何将其与ressource进行比较?因为我没有将entityTag附加到ressource 这只是比较entityTags。那么,我什么时候需要最后修改
抱歉,如果能为服务器端和客户端提供一个示例,那就太好了。我找不到关于这个问题的任何东西。如何在请求中发送EntityTag,如何在服务器端比较它们以及上次修改的内容。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();
}
对上次修改的表头以及etag和上次修改的表头提供了相同的支持
这篇维基百科文章很好地概述了ETag:这个例子是否应该没有request.evaluatePreconditions(et)?