Este contenido no está disponible en el idioma seleccionado.

27.3. Local Server-Side Response Cache


RESTEasy has a local, server-side, in-memory cache for your JAX-RS services. It automatically caches marshalled responses from HTTP GET JAX-RS invocations if your JAX-RS resource method sets a Cache-Control header. When a GET is received, the RESTEasy Server Cache checks whether the URI is stored in the cache. If true, the marshalled response is returned without invoking your JAX-RS method. Each cache entry has a maximum age for which the specifications in the Cache-Control header of the initial request are valid. The cache also automatically generates an ETag using an MD5 hash on the response body. This lets the client perform HTTP 1.1 cache revalidation with the IF-NONE-MATCH header. The cache will also perform revalidation if there is no initial cache hit, but the JAX-RS method returns a body with the same ETag.
To set up the server-side cache with Maven, you must use the resteasy-cache-core artifact:
<dependency>
   <groupId>org.jboss.resteasy</groupId>
   <artifactId>resteasy-cache-core</artifactId>
   <version>1.1.GA</version>
</dependency>
Copy to Clipboard Toggle word wrap
Next, add a ServletContextListener: org.jboss.resteasy.plugins.cache.server.ServletServerCache. You must specify this after the ResteasyBootstrap listener in your web.xml file.
<web-app>
    <listener>
        <listener-class>
            org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
        </listener-class>
    </listener>

    <context-param>
        <param-name>resteasy.server.cache.maxsize</param-name>
        <param-value>1000</param-value>
    </context-param>

    <context-param>
        <param-name>resteasy.server.cache.eviction.wakeup.interval</param-name>
        <param-value>5000</param-value>
    </context-param>

    <listener>
        <listener-class>
            org.jboss.resteasy.plugins.cache.server.ServletServerCache
        </listener-class>
    </listener>

    <servlet>
        <servlet-name>Resteasy</servlet-name>
        <servlet-class>
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
        </servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>Resteasy</servlet-name>
        <url-pattern>/rest-services/*</url-pattern>
    </servlet-mapping>

</web-app>
Copy to Clipboard Toggle word wrap
The cache implementation is based on the JBoss Cache project. You can set two context-param configuration variables: resteasy.server.cache.maxsize sets the number of elements that can be cached, and resteasy.server.cache.eviction.wakeup.interval sets the rate at which the background eviction thread runs to purge the cache of stale entries.
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