Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.



Span
stylefont-size:2em;font-weight:bold
JAX-RS : Advanced Features

 


Table of Contents

JMS Support

...

Please see the Continuations page for more information.

Client-side caching

If the JAX-RS Response message contains a "Cache-Control" HTTP header, then it is possible to cache the Response payload on the client side using the CacheControlFeature. CacheControlFeature uses the javax.cache.Caching API (which is optional in cxf-rt-rs-client). Therefore, to use the CacheControlFeature it is necessary to add the javax.cache API as well as an implementation (such as EhCache). For example:

Code Block
xml
xml
<dependency>
    <groupId>javax.cache</groupId>
    <artifactId>cache-api</artifactId>
    <version>1.0.0</version>
</dependency>
<dependency>
    <groupId>org.ehcache</groupId>
    <artifactId>ehcache</artifactId>
    <version>3.0.3</version>
</dependency>

CacheControlFeature parses the Cache-Control header and caches the Response payload if appropriate for the "max-age" attribute of Cache-Control. The next time the client calls out to the remote service (only GET is supported for now), the Response payload is retrieved from the cache and returned instead (assuming it is not expired), thus avoiding an unnecessary round-trip. Here is an example:

Code Block
xml
xml
CacheControlFeature cacheControlFeature = new CacheControlFeature();
cacheControlFeature.setCacheResponseInputStream(true);
Client client = ClientBuilder.newBuilder()
                           .register(cacheControlFeature)
                           .build();
WebTarget target = client.target(endpointAddress);

// First call
Response response = target.request().get();
// Second call should be cached
target.request().get();

 

Server-side caching

Ehcache-Web and other similar frameworks can be used to provide an advanced support for the server-side caching.

...