このコンテンツは選択した言語では利用できません。

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.
トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat