Java Reference
In-Depth Information
max-age
max-age
This directive is how long (in seconds) the cache is valid. If both an
Expires
header and
a
max-age
directive are set in the same response, the
max-age
always takes precedence.
s-maxage
s-maxage
The
s-maxage
directive is the same as the
max-age
directive, but it specifies the maxim-
um time a shared, intermediary cache (like a proxy) is allowed to hold the data. This dir-
ective allows you to have different expiration times than the client.
Let's take a look at a simple example of a response to see
Cache-Control
in action:
HTTP
HTTP
/
1.1 200
OOK
Content-Type
:
application/xml
Cache-Control: private, no-store, max-age=300
<customers>...</customers>
In this example, the response is saying that only the client may cache the response. This re-
sponse is valid for 300 seconds and must not be stored on disk.
The JAX-RS specification provides
javax.ws.rs.core.CacheControl
, a simple class to
represent the
Cache-Control
header:
public
public class
class
CacheControl
CacheControl
{
public
public
CacheControl
() {...}
public
public static
static
CacheControl
valueOf
(
String value
)
throws
throws
IllegalArgumentException
{...}
public
public
boolean
boolean
isMustRevalidate
() {...}
public
public
void
void
setMustRevalidate
(
boolean
boolean
mustRevalidate
) {...}
public
public
boolean
boolean
isProxyRevalidate
() {...}
public
public
void
void
setProxyRevalidate
(
boolean
boolean
proxyRevalidate
) {...}
public
public
int
int
getMaxAge
() {...}
public
public
void
void
setMaxAge
(
int
int
maxAge
) {...}
public
public
int
int
getSMaxAge
() {...}
public
public
void
void
setSMaxAge
(
int
int
sMaxAge
) {...}
public
public
List
<
String
>
getNoCacheFields
() {...}
public
public
void
void
setNoCache
(
boolean
boolean
noCache
) {...}
public
public
boolean
boolean
isNoCache
() {...}
public
public
boolean
boolean
isPrivate
() {...}
public
public
List
<
String
>
getPrivateFields
() {...}
public
public
void
void
setPrivate
(
boolean
boolean
_private
) {...}
public
public
boolean
boolean
isNoTransform
() {...}
public
public
void
void
setNoTransform
(
boolean
boolean
noTransform
) {...}
public
public
boolean
boolean
isNoStore
() {...}