Reputation: 26094
I want to improve performance in my REST API, I have been reading about HTTP caching but I think that don't understand the concept. If I have this resource:
@GET
@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
public Response test() {
Car car = new Car();
car.setName("Just a car");
CacheControl cc = new CacheControl();
cc.setMaxAge(86400);
Response.ResponseBuilder builder = Response.ok(car);
builder.cacheControl(cc);
return builder.build();
}
What does it exactly mean? Does it mean that the petition won't be performed again until max age is reached? Or have I to handle Cache-Control header manually in the client? I'm confused, help me to understand it.
Thanks.
Upvotes: 1
Views: 2236
Reputation: 854
You can also try with this api jcabi
You dont have to implement any caching logic , just annotation will do the magic and you can use it at any level like controller or service or dao.
Upvotes: 2
Reputation: 379
to improve performance of REST api response timings :
if the api is being used by multiple different client the cache-control would not help. instead use caching framework which actually cache the response to send. say by using memcache or in-memory cache or file cache.
if wants to improve performance such that one client need not to hit the api again to avoid network calls. then cache-control headers is being used in client side with httpCaching. Also CDN's serves the caching purpose which off-loads the server to get a request.
Upvotes: 1