Este conteúdo não está disponível no idioma selecionado.

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.
Voltar ao topo
Red Hat logoGithubredditYoutubeTwitter

Aprender

Experimente, compre e venda

Comunidades

Sobre a documentação da Red Hat

Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.

Tornando o open source mais inclusivo

A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.

Sobre a Red Hat

Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.

Theme

© 2025 Red Hat