JBoss.orgCommunity Documentation

Chapter 5. Resteasy Caching Features

5.1. Client side
5.2. Server side

Client and server side caching facilities are Resteasy specific extensions of JAX-RS, and they each work differently in Resteasy 2 and Resteasy 3.

Resteasy 3 offers the same client side cache facility as Resteasy 2, but it is enabled differently, by way of org.jboss.resteasy.client.jaxrs.cache.BrowserCacheFeature, which implements the JAX-RS 2.0 class javax.ws.rs.core.Feature:

Client client = ClientBuilder.newClient();
String url = "http://localhost:8081/orders/{id}";
ResteasyWebTarget target = (ResteasyWebTarget) client.target(url);
BrowserCacheFeature cacheFeature = new BrowserCacheFeature();
target.register(cacheFeature);
String rtn = target.resolveTemplate("id", "1").request().get(String.class);
   

Client side caching also works for proxies:

@Path("/orders")
public interface OrderServiceClient
{
   @Path("{id}")
   @GET
   @Produces("application/xml")
   public Order getOrder(@PathParam("id") String id);
}
...
Client client = ClientBuilder.newClient();
String "http://localhost:8081";
ResteasyWebTarget target = (ResteasyWebTarget) client.target(url);
BrowserCacheFeature cacheFeature = new BrowserCacheFeature();
target.register(cacheFeature);
OrderServiceClient orderService = target.proxy(OrderServiceClient.class);
   

As in Resteasy 2, a server side caching facility that sits in front of JAX-RS resources is made available in Resteasy 3, but the default underlying cache in Resteasy 3 is Infinispan, which supercedes the JBoss Cache project. It is highly configurable, and the documentation should be consulted for additional information: http://infinispan.org/documentation/.

Server side caching is also enabled differently. Resteasy 3 uses the JAX-RS 2.0 javax.ws.rs.core.Feature facility, in the form of org.jboss.resteasy.plugins.cache.server.ServerCacheFeature, which should be registered via the javax.ws.rs.core.Application.