You can use any caching mechanism applicable for standard java along with jersey, for example Ehcache .
You only need to pay attention to make sure that your data in the backend has not changed.
Here is a simple example with Ehcache :
@GET @Path("{id}") public List<Data> getData(@PathParam("id") Long id) { Element element = CacheManager.getInstance().getCache("test").get(id); if(element == null) { Data value = fetchElementFromBackend(id); CacheManager.getInstance().getCache("test").put(new Element(id, value)); return value; } return element.getObjectValue(); }
flash
source share