Module bus.http

Class CacheControl

java.lang.Object
org.miaixz.bus.http.cache.CacheControl

public class CacheControl extends Object
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 Classes
    Modifier and Type
    Class
    Description
    static final class 
    A builder for creating Cache-Control request headers.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final CacheControl
    A cache control request directive that uses only the cache, even if the cached response is stale.
    static final CacheControl
    A cache control request directive that requires a network validation for the response.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Returns true if the response is immutable.
    boolean
    Returns true if this response should not be cached by a shared cache.
    boolean
    Returns true if this response may be cached by any cache.
    int
    Returns the maximum age of a cached response in seconds.
    int
    Returns the maximum staleness of a cached response in seconds.
    int
    Returns the minimum freshness of a cached response in seconds.
    boolean
    Returns true if the cache must revalidate the response with the origin server before using it.
    boolean
    Returns true if this cache control forbids caching of any kind.
    boolean
    Returns true if this cache control forbids storing the response in any cache.
    boolean
    Returns true if the cache should not transform the response.
    boolean
    Returns true if the cache should only use the cached response and not use the network.
    parse(Headers headers)
    Returns the cache directives of headers.
    int
    Returns the "s-maxage" directive, which is the max age for shared caches.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • FORCE_NETWORK

      public static final CacheControl 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

      public static final CacheControl 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

      public static CacheControl parse(Headers headers)
      Returns the cache directives of headers. 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:
      true if caching is forbidden.
    • noStore

      public boolean noStore()
      Returns true if this cache control forbids storing the response in any cache.
      Returns:
      true if 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:
      true if this response is private.
    • isPublic

      public boolean isPublic()
      Returns true if this response may be cached by any cache.
      Returns:
      true if 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:
      true if 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:
      true if only cached responses should be used.
    • noTransform

      public boolean noTransform()
      Returns true if the cache should not transform the response.
      Returns:
      true if transformations are forbidden.
    • immutable

      public boolean immutable()
      Returns true if the response is immutable.
      Returns:
      true if the response is immutable.
    • toString

      public String toString()
      Overrides:
      toString in class Object