@Documented @Target(value={TYPE,METHOD}) @Retention(value=RUNTIME) @StableMinor(version="12.4", sinceVersion="8.0") public @interface CacheControl
Cache-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. Any Cache-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();
}
}
Modifier and Type | Optional Element and Description |
---|---|
boolean |
isPrivate
Controls the
private setting of the Cache-Control header. |
int |
maxAge
Controls the
max-age setting of the Cache-Control header. |
boolean |
mustRevalidate
Controls the
must-revalidate setting of the Cache-Control header. |
boolean |
noCache
Controls the
no-cache setting of the Cache-Control header. |
boolean |
noStore
Controls the
no-store setting of the Cache-Control header. |
boolean |
noTransform
Controls the
no-transform setting of the Cache-Control header. |
boolean |
proxyRevalidate
Controls the
proxy-revalidate setting of the Cache-Control header. |
int |
sharedMaxAge
Controls the
s-max-age setting of the Cache-Control header. |
public abstract boolean isPrivate
private
setting of the Cache-Control
header.true
if private
must be included in the the Cache-Control
header.public abstract boolean noCache
no-cache
setting of the Cache-Control
header.true
if no-cache
must be included in the the Cache-Control
header.public abstract boolean noStore
no-store
setting of the Cache-Control
header.true
if no-store
must be included in the the Cache-Control
header.public abstract boolean noTransform
no-transform
setting of the Cache-Control
header.true
if no-transform
must be included in the the Cache-Control
header.public abstract boolean mustRevalidate
must-revalidate
setting of the Cache-Control
header.true
if must-revalidate
must be included in the the Cache-Control
header.public abstract boolean proxyRevalidate
proxy-revalidate
setting of the Cache-Control
header.true
if proxy-revalidate
must be included in the the Cache-Control
header.public abstract int maxAge
max-age
setting of the Cache-Control
header.public abstract int sharedMaxAge
s-max-age
setting of the Cache-Control
header.LumisXP 12.4.0.200625 - Copyright © 2006–2020 Lumis EIP Tecnologia da Informação LTDA. All Rights Reserved.