Package org.apache.hc.client5.http.cache
Class ResponseCacheControl
- java.lang.Object
-
- org.apache.hc.client5.http.cache.ResponseCacheControl
-
- All Implemented Interfaces:
CacheControl
@Contract(threading=IMMUTABLE) public final class ResponseCacheControl extends java.lang.Object implements CacheControl
Represents the value of the Cache-Control header in an HTTP response, which indicate whether and for how long the response can be cached by the client and intermediary proxies.The class provides methods to retrieve the maximum age of the response and the maximum age that applies to shared caches. The values are expressed in seconds, with -1 indicating that the value was not specified in the header.
Instances of this class are immutable, meaning that their values cannot be changed once they are set. To create an instance, use one of the constructors that take the desired values as arguments. Alternatively, use the default constructor to create an instance with both values set to -1, indicating that the header was not present in the response.
- Since:
- 5.4
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classResponseCacheControl.Builder
-
Field Summary
Fields Modifier and Type Field Description private booleancachePrivateThe isPrivate flag indicates whether the Cache-Control header includes the private directive.private booleancachePublicIndicates whether the Cache-Control header includes the "public" directive.static ResponseCacheControlDEFAULTprivate booleanimmutableFlag for the 'immutable' Cache-Control directive.private longmaxAgeThe max-age directive value.private booleanmustRevalidateIndicates whether the Cache-Control header includes the "must-revalidate" directive.private booleanmustUnderstandIndicates whether the Cache-Control header includes the "must-understand" directive.private booleannoCacheThe isNoCache flag indicates whether the Cache-Control header includes the no-cache directive.private java.util.Set<java.lang.String>noCacheFieldsA set of field names specified in the "no-cache" directive of the Cache-Control header.private booleannoStoreThe isNoStore flag indicates whether the Cache-Control header includes the no-store directive.private booleanproxyRevalidateIndicates whether the Cache-Control header includes the "proxy-revalidate" directive.private longsharedMaxAgeThe shared-max-age directive value.private longstaleIfErrorThe number of seconds that a cached stale response MAY be used to satisfy the request, regardless of other freshness information..private longstaleWhileRevalidateThe number of seconds that a stale response is considered fresh for the purpose of serving a response while a revalidation request is made to the origin server.private booleanundefined
-
Constructor Summary
Constructors Constructor Description ResponseCacheControl(long maxAge, long sharedMaxAge, boolean mustRevalidate, boolean noCache, boolean noStore, boolean cachePrivate, boolean proxyRevalidate, boolean cachePublic, long staleWhileRevalidate, long staleIfError, java.util.Set<java.lang.String> noCacheFields, boolean mustUnderstand, boolean immutable)Creates a new instance ofCacheControlwith the specified values.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ResponseCacheControl.Builderbuilder()longgetMaxAge()Returns the max-age value from the Cache-Control header.java.util.Set<java.lang.String>getNoCacheFields()Returns an unmodifiable set of field names specified in the "no-cache" directive of the Cache-Control header.longgetSharedMaxAge()Returns the shared-max-age value from the Cache-Control header.longgetStaleIfError()Returns the stale-if-error value from the Cache-Control header.longgetStaleWhileRevalidate()Returns the stale-while-revalidate value from the Cache-Control header.booleanisCachePrivate()Returns the private flag from the Cache-Control header.booleanisImmutable()Returns the 'immutable' Cache-Control directive status.booleanisMustRevalidate()Returns whether the must-revalidate directive is present in the Cache-Control header.booleanisMustUnderstand()Returns the must-understand directive from the Cache-Control header.booleanisNoCache()Returns the no-cache flag from the Cache-Control header.booleanisNoStore()Returns the no-store flag from the Cache-Control header.booleanisProxyRevalidate()Returns whether the proxy-revalidate value is set in the Cache-Control header.booleanisPublic()Returns whether the public value is set in the Cache-Control header.booleanisUndefined()Returns the 'immutable' Cache-Control directive status.java.lang.StringtoString()
-
-
-
Field Detail
-
maxAge
private final long maxAge
The max-age directive value.
-
sharedMaxAge
private final long sharedMaxAge
The shared-max-age directive value.
-
noCache
private final boolean noCache
The isNoCache flag indicates whether the Cache-Control header includes the no-cache directive.
-
noStore
private final boolean noStore
The isNoStore flag indicates whether the Cache-Control header includes the no-store directive.
-
cachePrivate
private final boolean cachePrivate
The isPrivate flag indicates whether the Cache-Control header includes the private directive.
-
mustRevalidate
private final boolean mustRevalidate
Indicates whether the Cache-Control header includes the "must-revalidate" directive.
-
proxyRevalidate
private final boolean proxyRevalidate
Indicates whether the Cache-Control header includes the "proxy-revalidate" directive.
-
cachePublic
private final boolean cachePublic
Indicates whether the Cache-Control header includes the "public" directive.
-
mustUnderstand
private final boolean mustUnderstand
Indicates whether the Cache-Control header includes the "must-understand" directive.
-
staleWhileRevalidate
private final long staleWhileRevalidate
The number of seconds that a stale response is considered fresh for the purpose of serving a response while a revalidation request is made to the origin server.
-
staleIfError
private final long staleIfError
The number of seconds that a cached stale response MAY be used to satisfy the request, regardless of other freshness information..
-
noCacheFields
private final java.util.Set<java.lang.String> noCacheFields
A set of field names specified in the "no-cache" directive of the Cache-Control header.
-
undefined
private final boolean undefined
-
immutable
private final boolean immutable
Flag for the 'immutable' Cache-Control directive. If this field is true, then the 'immutable' directive is present in the Cache-Control header. The 'immutable' directive is meant to inform a cache or user agent that the response body will not change over time, even though it may be requested multiple times.
-
DEFAULT
public static final ResponseCacheControl DEFAULT
-
-
Constructor Detail
-
ResponseCacheControl
ResponseCacheControl(long maxAge, long sharedMaxAge, boolean mustRevalidate, boolean noCache, boolean noStore, boolean cachePrivate, boolean proxyRevalidate, boolean cachePublic, long staleWhileRevalidate, long staleIfError, java.util.Set<java.lang.String> noCacheFields, boolean mustUnderstand, boolean immutable)Creates a new instance ofCacheControlwith the specified values.- Parameters:
maxAge- The max-age value from the Cache-Control header.sharedMaxAge- The shared-max-age value from the Cache-Control header.mustRevalidate- The must-revalidate value from the Cache-Control header.noCache- The no-cache value from the Cache-Control header.noStore- The no-store value from the Cache-Control header.cachePrivate- The private value from the Cache-Control header.proxyRevalidate- The proxy-revalidate value from the Cache-Control header.cachePublic- The public value from the Cache-Control header.staleWhileRevalidate- The stale-while-revalidate value from the Cache-Control header.staleIfError- The stale-if-error value from the Cache-Control header.noCacheFields- The set of field names specified in the "no-cache" directive of the Cache-Control header.mustUnderstand- The must-understand value from the Cache-Control header.immutable- The immutable value from the Cache-Control header.
-
-
Method Detail
-
getMaxAge
public long getMaxAge()
Returns the max-age value from the Cache-Control header.- Specified by:
getMaxAgein interfaceCacheControl- Returns:
- The max-age value.
-
getSharedMaxAge
public long getSharedMaxAge()
Returns the shared-max-age value from the Cache-Control header.- Returns:
- The shared-max-age value.
-
isNoCache
public boolean isNoCache()
Returns the no-cache flag from the Cache-Control header.- Specified by:
isNoCachein interfaceCacheControl- Returns:
- The no-cache flag.
-
isNoStore
public boolean isNoStore()
Returns the no-store flag from the Cache-Control header.- Specified by:
isNoStorein interfaceCacheControl- Returns:
- The no-store flag.
-
isCachePrivate
public boolean isCachePrivate()
Returns the private flag from the Cache-Control header.- Returns:
- The private flag.
-
isMustUnderstand
public boolean isMustUnderstand()
Returns the must-understand directive from the Cache-Control header.- Returns:
- The must-understand directive.
-
isMustRevalidate
public boolean isMustRevalidate()
Returns whether the must-revalidate directive is present in the Cache-Control header.- Returns:
trueif the must-revalidate directive is present, otherwisefalse
-
isProxyRevalidate
public boolean isProxyRevalidate()
Returns whether the proxy-revalidate value is set in the Cache-Control header.- Returns:
trueif proxy-revalidate is set,falseotherwise.
-
isPublic
public boolean isPublic()
Returns whether the public value is set in the Cache-Control header.- Returns:
trueif public is set,falseotherwise.
-
getStaleWhileRevalidate
public long getStaleWhileRevalidate()
Returns the stale-while-revalidate value from the Cache-Control header.- Returns:
- The stale-while-revalidate value.
-
getStaleIfError
public long getStaleIfError()
Returns the stale-if-error value from the Cache-Control header.- Specified by:
getStaleIfErrorin interfaceCacheControl- Returns:
- The stale-if-error value.
-
getNoCacheFields
public java.util.Set<java.lang.String> getNoCacheFields()
Returns an unmodifiable set of field names specified in the "no-cache" directive of the Cache-Control header.- Returns:
- The set of field names specified in the "no-cache" directive.
-
isUndefined
public boolean isUndefined()
Returns the 'immutable' Cache-Control directive status.- Returns:
- true if the 'immutable' directive is present in the Cache-Control header.
-
isImmutable
public boolean isImmutable()
Returns the 'immutable' Cache-Control directive status.- Returns:
- true if the 'immutable' directive is present in the Cache-Control header.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
builder
public static ResponseCacheControl.Builder builder()
-
-