Package org.restlet.data
Class CacheDirective
- java.lang.Object
-
- org.restlet.data.CacheDirective
-
- All Implemented Interfaces:
NamedValue<java.lang.String>
public final class CacheDirective extends java.lang.Object implements NamedValue<java.lang.String>
Directive for caching mechanisms along the call chain. This overrides the default behavior of those caches and proxies.
Note that when used with HTTP connectors, this class maps to the "Cache-Control" header.- Author:
- Jerome Louvel
-
-
Constructor Summary
Constructors Constructor Description CacheDirective(java.lang.String name)
Constructor for directives with no value.CacheDirective(java.lang.String name, java.lang.String value)
Constructor for directives with a value.CacheDirective(java.lang.String name, java.lang.String value, boolean digit)
Constructor for directives with a value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
java.lang.String
getName()
Returns the name.java.lang.String
getValue()
Returns the value.int
hashCode()
boolean
isDigit()
Returns true if the directive contains a digit value.static CacheDirective
maxAge(int maxAge)
Creates a "max-age" directive.static CacheDirective
maxStale()
Creates a "max-stale" directive.static CacheDirective
maxStale(int maxStale)
Creates a "max-stale" directive.static CacheDirective
minFresh(int minFresh)
Creates a "min-fresh" directive.static CacheDirective
mustRevalidate()
Creates a "must-revalidate" directive.static CacheDirective
noCache()
Creates a "no-cache" directive.static CacheDirective
noCache(java.lang.String fieldName)
Creates a "no-cache" directive.static CacheDirective
noCache(java.util.List<java.lang.String> fieldNames)
Creates a "no-cache" directive.static CacheDirective
noStore()
Creates a "no-store" directive.static CacheDirective
noTransform()
Creates a "no-transform" directive.static CacheDirective
onlyIfCached()
Creates a "onlyIfCached" directive.static CacheDirective
privateInfo()
Creates a "private" directive.static CacheDirective
privateInfo(java.lang.String fieldName)
Creates a "private" directive.static CacheDirective
privateInfo(java.util.List<java.lang.String> fieldNames)
Creates a "private" directive.static CacheDirective
proxyMustRevalidate()
Creates a "proxy-revalidate" directive.static CacheDirective
publicInfo()
Creates a "public" directive.void
setDigit(boolean digit)
Indicates if the directive is a digit value.void
setName(java.lang.String name)
Sets the name.void
setValue(java.lang.String value)
Sets the value.static CacheDirective
sharedMaxAge(int sharedMaxAge)
Creates a "s-maxage" directive.java.lang.String
toString()
-
-
-
Constructor Detail
-
CacheDirective
public CacheDirective(java.lang.String name)
Constructor for directives with no value.- Parameters:
name
- The directive name.
-
CacheDirective
public CacheDirective(java.lang.String name, java.lang.String value)
Constructor for directives with a value.- Parameters:
name
- The directive name.value
- The directive value.
-
CacheDirective
public CacheDirective(java.lang.String name, java.lang.String value, boolean digit)
Constructor for directives with a value.- Parameters:
name
- The directive name.value
- The directive value.digit
- The kind of value (true for a digit value, false otherwise).
-
-
Method Detail
-
maxAge
public static CacheDirective maxAge(int maxAge)
Creates a "max-age" directive. Indicates that the client is willing to accept a response whose age is no greater than the specified time in seconds. Unless "max-stale" directive is also included, the client is not willing to accept a stale response.
Note that this directive can be used on requests or responses.- Parameters:
maxAge
- Maximum age in seconds.- Returns:
- A new "max-age" directive.
- See Also:
- HTTP 1.1 - Modifications of the Basic Expiration Mechanism, HTTP 1.1 - Cache Revalidation and Reload Controls
-
maxStale
public static CacheDirective maxStale()
Creates a "max-stale" directive. Indicates that the client is willing to accept a response that has exceeded its expiration time by any amount of time.
Note that this directive can be used on requests only.- Returns:
- A new "max-stale" directive.
- See Also:
- HTTP 1.1 - Modifications of the Basic Expiration Mechanism
-
maxStale
public static CacheDirective maxStale(int maxStale)
Creates a "max-stale" directive. Indicates that the client is willing to accept a response that has exceeded its expiration time by a given amount of time.
Note that this directive can be used on requests only.- Parameters:
maxStale
- Maximum stale age in seconds.- Returns:
- A new "max-stale" directive.
- See Also:
- HTTP 1.1 - Modifications of the Basic Expiration Mechanism
-
minFresh
public static CacheDirective minFresh(int minFresh)
Creates a "min-fresh" directive. Indicates that the client is willing to accept a response whose freshness lifetime is no less than its current age plus the specified time in seconds. That is, the client wants a response that will still be fresh for at least the specified number of seconds.
Note that this directive can be used on requests only.- Parameters:
minFresh
- Minimum freshness lifetime in seconds.- Returns:
- A new "min-fresh" directive.
- See Also:
- HTTP 1.1 - Modifications of the Basic Expiration Mechanism
-
mustRevalidate
public static CacheDirective mustRevalidate()
Creates a "must-revalidate" directive. Indicates that the origin server requires revalidation of a cache entry on any subsequent use.
Note that this directive can be used on responses only.- Returns:
- A new "must-revalidate" directive.
- See Also:
- HTTP 1.1 - Cache Revalidation and Reload Controls
-
noCache
public static CacheDirective noCache()
Creates a "no-cache" directive. Indicates that a cache must not use the response to satisfy subsequent requests without successful revalidation with the origin server.
Note that this directive can be used on requests or responses.- Returns:
- A new "no-cache" directive.
- See Also:
- HTTP 1.1 - What is Cacheable
-
noCache
public static CacheDirective noCache(java.util.List<java.lang.String> fieldNames)
Creates a "no-cache" directive. Indicates that a cache must not use the response to satisfy subsequent requests without successful revalidation with the origin server.
Note that this directive can be used on requests or responses.- Parameters:
fieldNames
- Field names, typically a HTTP header name, that must not be sent by caches.- Returns:
- A new "no-cache" directive.
- See Also:
- HTTP 1.1 - What is Cacheable
-
noCache
public static CacheDirective noCache(java.lang.String fieldName)
Creates a "no-cache" directive. Indicates that a cache must not use the response to satisfy subsequent requests without successful revalidation with the origin server.
Note that this directive can be used on requests or responses.- Parameters:
fieldName
- A field name, typically a HTTP header name, that must not be sent by caches.- Returns:
- A new "no-cache" directive.
- See Also:
- HTTP 1.1 - What is Cacheable
-
noStore
public static CacheDirective noStore()
Creates a "no-store" directive. Indicates that a cache must not release or retain any information about the call. This applies to both private and shared caches.
Note that this directive can be used on requests or responses.- Returns:
- A new "no-store" directive.
- See Also:
- HTTP 1.1 - What May be Stored by Caches
-
noTransform
public static CacheDirective noTransform()
Creates a "no-transform" directive. Indicates that a cache or intermediary proxy must not transform the response entity.
Note that this directive can be used on requests or responses.- Returns:
- A new "no-transform" directive.
- See Also:
- HTTP 1.1 - No-Transform Directive
-
onlyIfCached
public static CacheDirective onlyIfCached()
Creates a "onlyIfCached" directive. Indicates that only cached responses should be returned to the client.
Note that this directive can be used on requests only.- Returns:
- A new "only-if-cached" directive.
- See Also:
- HTTP 1.1 - Cache Revalidation and Reload Controls
-
privateInfo
public static CacheDirective privateInfo()
Creates a "private" directive. Indicates that all or part of the response message is intended for a single user and must not be cached by a shared cache.
Note that this directive can be used on responses only.- Returns:
- A new "private" directive.
- See Also:
- HTTP 1.1 - What is Cacheable
-
privateInfo
public static CacheDirective privateInfo(java.util.List<java.lang.String> fieldNames)
Creates a "private" directive. Indicates that all or part of the response message is intended for a single user and must not be cached by a shared cache.
Note that this directive can be used on responses only.- Parameters:
fieldNames
- Field names, typically a HTTP header name, that must be private.- Returns:
- A new "private" directive.
- See Also:
- HTTP 1.1 - What is Cacheable
-
privateInfo
public static CacheDirective privateInfo(java.lang.String fieldName)
Creates a "private" directive. Indicates that all or part of the response message is intended for a single user and must not be cached by a shared cache.
Note that this directive can be used on responses only.- Parameters:
fieldName
- A field name, typically a HTTP header name, that is private.- Returns:
- A new "private" directive.
- See Also:
- HTTP 1.1 - What is Cacheable
-
proxyMustRevalidate
public static CacheDirective proxyMustRevalidate()
Creates a "proxy-revalidate" directive. Indicates that the origin server requires revalidation of a cache entry on any subsequent use, except that it does not apply to non-shared user agent caches
Note that this directive can be used on responses only.- Returns:
- A new "proxy-revalidate" directive.
- See Also:
- HTTP 1.1 - Cache Revalidation and Reload Controls
-
publicInfo
public static CacheDirective publicInfo()
Creates a "public" directive. Indicates that the response may be cached by any cache, even if it would normally be non-cacheable or cacheable only within a non-shared cache.
Note that this directive can be used on responses only.- Returns:
- A new "public" directive.
- See Also:
- HTTP 1.1 - What is Cacheable
-
sharedMaxAge
public static CacheDirective sharedMaxAge(int sharedMaxAge)
Creates a "s-maxage" directive. Indicates that the client is willing to accept a response from a shared cache (but not a private cache) whose age is no greater than the specified time in seconds.
Note that this directive can be used on responses only.- Parameters:
sharedMaxAge
- Maximum age in seconds.- Returns:
- A new "s-maxage" directive.
- See Also:
- HTTP 1.1 - Modifications of the Basic Expiration Mechanism
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
getName
public java.lang.String getName()
Returns the name.- Specified by:
getName
in interfaceNamedValue<java.lang.String>
- Returns:
- The name.
-
getValue
public java.lang.String getValue()
Returns the value.- Specified by:
getValue
in interfaceNamedValue<java.lang.String>
- Returns:
- The value.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
isDigit
public boolean isDigit()
Returns true if the directive contains a digit value.- Returns:
- True if the directive contains a digit value.
-
setDigit
public void setDigit(boolean digit)
Indicates if the directive is a digit value.- Parameters:
digit
- True if the directive contains a digit value.
-
setName
public void setName(java.lang.String name)
Sets the name.- Parameters:
name
- The name.
-
setValue
public void setValue(java.lang.String value)
Sets the value.- Specified by:
setValue
in interfaceNamedValue<java.lang.String>
- Parameters:
value
- The value.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-