Question

I was thinking of leveraging the cachecontrol option in JAX-RS.

But all i know and fully understand is, its used in GET and PUT requests. Has anyone ever tried using it for a POST request?

I am building a RESTful webservice that caters to client's requests. It internally forwards client's request to another component and dumps the response back to the client. The response is same for identical requests.

How can i use caching to sometimes directly respond from the cache instead of forwarding/receiving response from the the internal component?

I can't use a database or nosql dDB for caching request/response. I want something in memory that is lost once application restarts.

Was it helpful?

Solution

HTTP has methods that are safe or unsafe, and methods that are idempotent or not idempotet. See the HTTP spec:

Methods can also have the property of "idempotence" in that (aside from error or expiration issues) the side-effects of N > 0 identical requests is the same as for a single request. The methods GET, HEAD, PUT and DELETE share this property.

You can GET, PUT, or DELETE a Resources as often as you like, the result will be the same, no matter how often you do it.

As you see, POST is not idempotet. It makes a difference to POST a request to a Resource once, twice, or more often. That's because the semantics of POST is to create something below the Resource you POST to.

Because of all this, it makes no sense to cache the result of a POST request.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top