Ce contenu n'est pas disponible dans la langue sélectionnée.

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.
Retour au début
Red Hat logoGithubredditYoutubeTwitter

Apprendre

Essayez, achetez et vendez

Communautés

À propos de la documentation Red Hat

Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance. Découvrez nos récentes mises à jour.

Rendre l’open source plus inclusif

Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez le Blog Red Hat.

À propos de Red Hat

Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.

Theme

© 2025 Red Hat