Este contenido no está disponible en el idioma seleccionado.

27.2. Client "Browser" Cache


RESTEasy can create a client-side, browser-like cache for use with the Client Proxy Framework or with raw ClientRequests. This cache locates Cache-Control headers that are returned with a server response. If the Cache-Control headers specify that the client may cache the response, RESTEasy caches it within local memory. This cache obeys max-age requirements, and automatically performs HTTP 1.1 cache revalidation if either or both of the Last-Modified or ETag headers are returned with the original response. (See the HTTP 1.1 specification for details about Cache-Control or cache revalidation.)
Enabling RESTEasy caching is simple. The following shows the client cache being used with the Client Proxy Framework:
@Path("/orders")
public interface OrderServiceClient {

   @Path("{id}")
   @GET
   @Produces("application/xml")
   public Order getOrder(@PathParam("id") String id);
}
Copy to Clipboard Toggle word wrap
You can create a proxy for this interface and enable caching for that proxy like so:
import org.jboss.resteasy.client.ProxyFactory;
import org.jboss.resteasy.client.cache.CacheFactory;
import org.jboss.resteasy.client.cache.LightweightBrowserCache;

public static void main(String[] args) throws Exception
{
      RegisterBuiltin.register(ResteasyProviderFactory.getInstance());
      OrderServiceClient proxy = ProxyFactory.create(OrderServiceClient.class, generateBaseUrl());

      // This line enables caching
      LightweightBrowserCache cache = CacheFactory.makeCacheable(proxy);
}
Copy to Clipboard Toggle word wrap
If you are using the ClientRequest class instead of the proxy server to perform invocations, you can enable the cache like so:
import org.jboss.resteasy.client.ProxyFactory;
import org.jboss.resteasy.client.cache.CacheFactory;
import org.jboss.resteasy.client.cache.LightweightBrowserCache;

public static void main(String[] args) throws Exception
{
      RegisterBuiltin.register(ResteasyProviderFactory.getInstance());

      // This line enables caching
      LightweightBrowserCache cache = new LightweightBrowserCache();

      ClientRequest request = new ClientRequest("http://example.com/orders/333");
      CacheFactory.makeCacheable(request, cache);
}
Copy to Clipboard Toggle word wrap
By default, the LightweightBrowserCache has a maximum caching space of two megabytes. You can change this programmatically by calling the setMaxBytes() method. If the cache becomes full, all cached data will be deleted automatically. For more complex caching solutions, or support for third-party cache options, contact the resteasy-development list and discuss your ideas with the community.
Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2025 Red Hat