...
Span | ||
---|---|---|
| ||
JAX-RS : Advanced Features |
Table of Contents |
---|
JMS Support
...
CacheControlFeature parses the Cache-Control header and caches the Response payload if appropriate for the "max-age" attribute of Cache-Control (or the "Expires" HTTP header if max-age is not specified). 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 | ||||
---|---|---|---|---|
| ||||
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(); |
If the initial response from the service contains an "ETag" HTTP header, then once the message has expired, CXF will send this value to the service as the "If-None-Match" header. Similarly, "Last-Modified" is sent as "If-Modified-Since". The CXF client will also cache the expired payload. If the service responds with a 304 status code, then the old message payload is returned to the client.
Server-side caching
Ehcache-Web and other similar frameworks can be used to provide an advanced support for the server-side caching.
...