Module methanol

Class CacheControl

java.lang.Object
com.github.mizosoft.methanol.CacheControl

public final class CacheControl extends Object
A group of cache directives.

CacheControl provides type-safe accessors for the directives specified in RFC 7234. Additionally, there's support for the stale-while-revalidate & stale-if-error extensions specified in RFC 5861. Other Cache-Control extensions can be accessed using the directives() map.

See Also:
  • Method Details

    • directives

      public Map<String,String> directives()
      Returns a map of all directives and their arguments. Directives that don't have arguments are mapped to an empty string.
    • maxAge

      public Optional<Duration> maxAge()
      Returns the value of the max-age directive if present.
    • sMaxAge

      public Optional<Duration> sMaxAge()
      Returns the value of the s-maxage directive if present.
    • minFresh

      public Optional<Duration> minFresh()
      Returns the value of the min-fresh directive if present.
    • maxStale

      public Optional<Duration> maxStale()
      Returns the value of the max-stale directive if present.
    • anyMaxStale

      public boolean anyMaxStale()
      Returns whether the max-stale directive is present but has no value, which indicates that a response with any staleness is acceptable.
    • staleWhileRevalidate

      public Optional<Duration> staleWhileRevalidate()
      Returns the value of the stale-while-revalidate directive if present.
    • staleIfError

      public Optional<Duration> staleIfError()
      Returns the value of the stale-if-error directive if present.
    • noCache

      public boolean noCache()
      Returns true if the no-cache directive is set.
    • noCacheFields

      public Set<String> noCacheFields()
      Returns the header fields nominated by no-cache if specified.
    • noStore

      public boolean noStore()
      Returns true if the no-store directive is set.
    • noStoreFields

      public Set<String> noStoreFields()
      Returns the header fields nominated by no-store if specified.
    • noTransform

      public boolean noTransform()
      Returns true if the no-transform directive is set.
    • isPublic

      public boolean isPublic()
      Returns true if the public directive is set.
    • isPrivate

      public boolean isPrivate()
      Returns true if the private directive is set.
    • privateFields

      public Set<String> privateFields()
      Returns the header fields nominated by private if specified.
    • onlyIfCached

      public boolean onlyIfCached()
      Returns true if the only-if-cached directive is set.
    • mustRevalidate

      public boolean mustRevalidate()
      Returns true if the must-revalidate directive is set.
    • proxyRevalidate

      public boolean proxyRevalidate()
      Returns true if the proxy-revalidate directive is set.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • parse

      public static CacheControl parse(String value)
      Parses the cache directives specified by the given value.
      Throws:
      IllegalArgumentException - if the given value has invalid cache directives
    • parse

      public static CacheControl parse(List<String> values)
      Parses the cache directives specified by each of the given values.
      Throws:
      IllegalArgumentException - if any of the given values has invalid cache directives
    • parse

      public static CacheControl parse(HttpHeaders headers)
      Parses the cache directives specified by the given headers.
      Throws:
      IllegalArgumentException - if the given headers have any invalid cache directives
    • newBuilder

      public static CacheControl.Builder newBuilder()
      Returns a new Builder.
    • empty

      public static CacheControl empty()
      Returns a CacheControl with no directives.