java.lang.Object
org.miaixz.bus.http.cache.CacheControl
A cache control header with caching directives from a server or client. These directives set the policy for which
responses can be stored, and which requests can be satisfied by a stored response.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA builder for creatingCache-Controlrequest headers. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final CacheControlA cache control request directive that uses only the cache, even if the cached response is stale.static final CacheControlA cache control request directive that requires a network validation for the response. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true if the response is immutable.booleanReturns true if this response should not be cached by a shared cache.booleanisPublic()Returns true if this response may be cached by any cache.intReturns the maximum age of a cached response in seconds.intReturns the maximum staleness of a cached response in seconds.intReturns the minimum freshness of a cached response in seconds.booleanReturns true if the cache must revalidate the response with the origin server before using it.booleannoCache()Returns true if this cache control forbids caching of any kind.booleannoStore()Returns true if this cache control forbids storing the response in any cache.booleanReturns true if the cache should not transform the response.booleanReturns true if the cache should only use the cached response and not use the network.static CacheControlReturns the cache directives ofheaders.intReturns the "s-maxage" directive, which is the max age for shared caches.toString()
-
Field Details
-
FORCE_NETWORK
A cache control request directive that requires a network validation for the response. Note that the cache may assist these requests with conditional GET requests. -
FORCE_CACHE
A cache control request directive that uses only the cache, even if the cached response is stale. If the response is not available in the cache or requires server validation, the call will fail.
-
-
Method Details
-
parse
Returns the cache directives ofheaders. If both Cache-Control and Pragma headers are present, they are merged.- Parameters:
headers- The headers to parse.- Returns:
- The cache control header.
-
noCache
public boolean noCache()Returns true if this cache control forbids caching of any kind.- Returns:
trueif caching is forbidden.
-
noStore
public boolean noStore()Returns true if this cache control forbids storing the response in any cache.- Returns:
trueif storing is forbidden.
-
maxAgeSeconds
public int maxAgeSeconds()Returns the maximum age of a cached response in seconds.- Returns:
- The max age in seconds.
-
sMaxAgeSeconds
public int sMaxAgeSeconds()Returns the "s-maxage" directive, which is the max age for shared caches.- Returns:
- The s-maxage in seconds.
-
isPrivate
public boolean isPrivate()Returns true if this response should not be cached by a shared cache.- Returns:
trueif this response is private.
-
isPublic
public boolean isPublic()Returns true if this response may be cached by any cache.- Returns:
trueif this response is public.
-
mustRevalidate
public boolean mustRevalidate()Returns true if the cache must revalidate the response with the origin server before using it.- Returns:
trueif revalidation is required.
-
maxStaleSeconds
public int maxStaleSeconds()Returns the maximum staleness of a cached response in seconds.- Returns:
- The max stale in seconds.
-
minFreshSeconds
public int minFreshSeconds()Returns the minimum freshness of a cached response in seconds.- Returns:
- The min fresh in seconds.
-
onlyIfCached
public boolean onlyIfCached()Returns true if the cache should only use the cached response and not use the network.- Returns:
trueif only cached responses should be used.
-
noTransform
public boolean noTransform()Returns true if the cache should not transform the response.- Returns:
trueif transformations are forbidden.
-
immutable
public boolean immutable()Returns true if the response is immutable.- Returns:
trueif the response is immutable.
-
toString
-