Annotation Type CacheControl
-
@Documented @Target({TYPE,METHOD}) @Retention(RUNTIME) @StableMinor(version="14.0", sinceVersion="8.0") public @interface CacheControl
An annotation which specifies theCache-Control
header to include in the response produced by the annotated method.This annotation may be applied to a REST method or to its class. If it is present in both the method and the class, the one present in the method is the one used.
When no
Cache-Control
header is present in the response, a header according to this annotation present in the method or class will be added to the response (note that if the values of this annotation corresponds to an empty header, it will not be added).If the response already has a
Cache-Control
header present, it is not modified, independently of this annotation. AnyCache-Control
header set in the response is considered to override this annotation or the default behavior.If neither a
Cache-Control
header is in the response or this annotation is applied, LumisXP includes the following response header as default:
Cache-Control: private, no-cache, no-store, no-transform
Example:
@CacheControl(maxAge=60) public class MyRest { @GET @Path("/hello1") @Produces({MediaType.TEXT_PLAIN}) public String helloCachedFor60Seconds() { // since this method does not have @CacheControl but the class has it, the one in the class will be used, specifying max-age=60 // Note that the actual use of cache depends on the HTTP client being used. return new java.util.Date().toString(); } @GET @Path("/hello2") @Produces({MediaType.TEXT_PLAIN}) @CacheControl public String helloNoCacheControlHeader() { // the @CacheControl in this method will not generate any Cache-Control header return new java.util.Date().toString(); } @GET @Path("/hello3") @Produces({MediaType.TEXT_PLAIN}) @CacheControl(noCache=true) public String helloNoCache() { // the @CacheControl annotation in this method will generate a no-cache header return new java.util.Date().toString(); } }
- Since:
- 8.0.0
- Version:
- $Revision: 24477 $ $Date: 2021-04-28 11:30:36 -0300 (Wed, 28 Apr 2021) $
- See Also:
- HTTP Cache-Control header specification
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description boolean
isPrivate
Controls theprivate
setting of theCache-Control
header.int
maxAge
Controls themax-age
setting of theCache-Control
header.boolean
mustRevalidate
Controls themust-revalidate
setting of theCache-Control
header.boolean
noCache
Controls theno-cache
setting of theCache-Control
header.boolean
noStore
Controls theno-store
setting of theCache-Control
header.boolean
noTransform
Controls theno-transform
setting of theCache-Control
header.boolean
proxyRevalidate
Controls theproxy-revalidate
setting of theCache-Control
header.int
sharedMaxAge
Controls thes-max-age
setting of theCache-Control
header.
-
-
-
Element Detail
-
isPrivate
boolean isPrivate
Controls theprivate
setting of theCache-Control
header.- Returns:
true
ifprivate
must be included in the theCache-Control
header.- Since:
- 8.0.0
- See Also:
- HTTP Cache-Control header specification
- Default:
- false
-
-
-
noCache
boolean noCache
Controls theno-cache
setting of theCache-Control
header.- Returns:
true
ifno-cache
must be included in the theCache-Control
header.- Since:
- 8.0.0
- See Also:
- HTTP Cache-Control header specification
- Default:
- false
-
-
-
noStore
boolean noStore
Controls theno-store
setting of theCache-Control
header.- Returns:
true
ifno-store
must be included in the theCache-Control
header.- Since:
- 8.0.0
- See Also:
- HTTP Cache-Control header specification
- Default:
- false
-
-
-
noTransform
boolean noTransform
Controls theno-transform
setting of theCache-Control
header.- Returns:
true
ifno-transform
must be included in the theCache-Control
header.- Since:
- 8.0.0
- See Also:
- HTTP Cache-Control header specification
- Default:
- false
-
-
-
mustRevalidate
boolean mustRevalidate
Controls themust-revalidate
setting of theCache-Control
header.- Returns:
true
ifmust-revalidate
must be included in the theCache-Control
header.- Since:
- 8.0.0
- See Also:
- HTTP Cache-Control header specification
- Default:
- false
-
-
-
proxyRevalidate
boolean proxyRevalidate
Controls theproxy-revalidate
setting of theCache-Control
header.- Returns:
true
ifproxy-revalidate
must be included in the theCache-Control
header.- Since:
- 8.0.0
- See Also:
- HTTP Cache-Control header specification
- Default:
- false
-
-
-
maxAge
int maxAge
Controls themax-age
setting of theCache-Control
header.- Returns:
- the number of seconds for which the response should be considered fresh, or -1 to disable this setting.
- Since:
- 8.0.0
- See Also:
- HTTP Cache-Control header specification
- Default:
- -1
-
-
-
sharedMaxAge
int sharedMaxAge
Controls thes-max-age
setting of theCache-Control
header.- Returns:
- the number of seconds for which the response should be considered fresh in shared caches, or -1 to disable this setting.
- Since:
- 8.0.0
- See Also:
- HTTP Cache-Control header specification
- Default:
- -1
-
-