Module methanol

Class CacheControl


  • public final class CacheControl
    extends java.lang.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:
    Caching - CacheControl for an overview of the semantics of supported cache directives.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  CacheControl.Builder
      A builder of CacheControl instances, with explicit directive setters for request cache directives.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean anyMaxStale()
      Returns whether the max-stale directive is present but has no value, which indicates that a response with any staleness is acceptable.
      java.util.Map<java.lang.String,​java.lang.String> directives()
      Returns a map of all directives and their arguments.
      static CacheControl empty()
      Returns a CacheControl with no directives.
      boolean equals​(@Nullable java.lang.Object obj)  
      int hashCode()  
      boolean isPrivate()
      Returns true if the private directive is set.
      boolean isPublic()
      Returns true if the public directive is set.
      java.util.Optional<java.time.Duration> maxAge()
      Returns the value of the max-age directive if present.
      java.util.Optional<java.time.Duration> maxStale()
      Returns the value of the max-stale directive if present.
      java.util.Optional<java.time.Duration> minFresh()
      Returns the value of the min-fresh directive if present.
      boolean mustRevalidate()
      Returns true if the must-revalidate directive is set.
      static CacheControl.Builder newBuilder()
      Returns a new Builder.
      boolean noCache()
      Returns true if the no-cache directive is set.
      java.util.Set<java.lang.String> noCacheFields()
      Returns the header fields nominated by no-cache if specified.
      boolean noStore()
      Returns true if the no-store directive is set.
      java.util.Set<java.lang.String> noStoreFields()
      Returns the header fields nominated by no-store if specified.
      boolean noTransform()
      Returns true if the no-transform directive is set.
      boolean onlyIfCached()
      Returns true if the only-if-cached directive is set.
      static CacheControl parse​(java.lang.String value)
      Parses the cache directives specified by the given value.
      static CacheControl parse​(java.net.http.HttpHeaders headers)
      Parses the cache directives specified by the given headers.
      static CacheControl parse​(java.util.List<java.lang.String> values)
      Parses the cache directives specified by each of the given values.
      java.util.Set<java.lang.String> privateFields()
      Returns the header fields nominated by private if specified.
      boolean proxyRevalidate()
      Returns true if the proxy-revalidate directive is set.
      java.util.Optional<java.time.Duration> sMaxAge()
      Returns the value of the s-maxage directive if present.
      java.util.Optional<java.time.Duration> staleIfError()
      Returns the value of the stale-if-error directive if present.
      java.util.Optional<java.time.Duration> staleWhileRevalidate()
      Returns the value of the stale-while-revalidate directive if present.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Method Detail

      • directives

        public java.util.Map<java.lang.String,​java.lang.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 java.util.Optional<java.time.Duration> maxAge()
        Returns the value of the max-age directive if present.
      • sMaxAge

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

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

        public java.util.Optional<java.time.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 java.util.Optional<java.time.Duration> staleWhileRevalidate()
        Returns the value of the stale-while-revalidate directive if present.
      • staleIfError

        public java.util.Optional<java.time.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 java.util.Set<java.lang.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 java.util.Set<java.lang.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 java.util.Set<java.lang.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​(@Nullable java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

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

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

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

        public static CacheControl parse​(java.net.http.HttpHeaders headers)
        Parses the cache directives specified by the given headers.
        Throws:
        java.lang.IllegalArgumentException - if the given headers have any invalid cache directives
      • empty

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