The HTTP Cache-Control directive defines the HTTP response caching policies. You can use it for enabling the caching of the RESTful web API results for a specified interval. Here is a quick summary of the important HTTP Cache-Control directives:
HTTP Cache-Control directive |
Description |
public |
In this directive, public resources can be cached by the client and all intermediate public proxies. |
private |
In this directive, private resources can be cached only by the client. |
max-age |
This directive specifies how long a resource cached on the client is valid (measured in seconds). |
smax-age |
This property specifies the maximum age for a shared cache such as proxy cache (for example, content delivery network). |
no-cache |
This directive indicates that the resource should not be cached. |
no-store |
This directive indicates that the cached resource should not be stored on disk; however, it can be cached in-memory. |
must-revalidate |
This directive indicates that once the cache expires, the cache must revalidate the resource with the origin server even if the client is willing to work on the stale resource. |
JAX-RS allows you to specify the Cache-Control directives on the javax.ws.rs.core.Response object via the javax.ws.rs.core.CacheControl class. To learn how to use the CacheControl class in your JAX-RS resource class, refer to the Using Cache-Control directives to manage the HTTP cache section in Chapter 4, Advanced Features in the JAX-RS APIs.