EntityTag - cost, caching, comparison - like in Jersey

at the moment when I am trying to enable caching for my jersey support team.

So, some questions arise.

  • What does entityTag mean? Could this be a unique random string generated?

  • When I make a mail request from my client to the server, I return a response with an entity tag. Question: how to cache this and how do I know which cached EntTag object I should send for the next receive request?

  • On the server side, I get send entityTag. How to compare this with ressource? Because I did not bind entityTag to ressource.

  • This is just a comparison of entities. So, when do I need the value of the last modified header?

Sorry, it would be nice to get an example for the server and client. I can not find anything for this problem. How to send the Tags entity to the request, how to compare them on the server side and what are the latest changes.

+5
source share
1 answer

ETags provide a mechanism for the client’s cache to check whether it stores cached content. Regarding your questions:

  • Before the server decides, it must uniquely identify the version of the resource at a given time (there may be a revision number of the resource or a hash hash of the CRC32 representation of the resources or something else that can be used to determine if the resource has changed)
  • . , ClientFilter, , HashMap (), URI, . ETag . , , 304 ( ), , , , , , .
  • entity , : " , , - ? , !". , , , . - .
  • , .

ETags . . :

@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, last-modified.

ETags: http://en.wikipedia.org/wiki/HTTP_ETag

+7

All Articles