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:
You can create a proxy for this interface and enable caching for that proxy like so:
If you are using the
ClientRequest class instead of the proxy server to perform invocations, you can enable the cache like so:
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.