Class 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
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static ResponseCacheControl.Builder builder()  
      long getMaxAge()
      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.
      long getSharedMaxAge()
      Returns the shared-max-age value from the Cache-Control header.
      long getStaleIfError()
      Returns the stale-if-error value from the Cache-Control header.
      long getStaleWhileRevalidate()
      Returns the stale-while-revalidate value from the Cache-Control header.
      boolean isCachePrivate()
      Returns the private flag from the Cache-Control header.
      boolean isImmutable()
      Returns the 'immutable' Cache-Control directive status.
      boolean isMustRevalidate()
      Returns whether the must-revalidate directive is present in the Cache-Control header.
      boolean isMustUnderstand()
      Returns the must-understand directive from the Cache-Control header.
      boolean isNoCache()
      Returns the no-cache flag from the Cache-Control header.
      boolean isNoStore()
      Returns the no-store flag from the Cache-Control header.
      boolean isProxyRevalidate()
      Returns whether the proxy-revalidate value is set in the Cache-Control header.
      boolean isPublic()
      Returns whether the public value is set in the Cache-Control header.
      boolean isUndefined()
      Returns the 'immutable' Cache-Control directive status.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • getMaxAge

        public long getMaxAge()
        Returns the max-age value from the Cache-Control header.
        Specified by:
        getMaxAge in interface CacheControl
        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:
        isNoCache in interface CacheControl
        Returns:
        The no-cache flag.
      • isNoStore

        public boolean isNoStore()
        Returns the no-store flag from the Cache-Control header.
        Specified by:
        isNoStore in interface CacheControl
        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:
        true if the must-revalidate directive is present, otherwise false
      • isProxyRevalidate

        public boolean isProxyRevalidate()
        Returns whether the proxy-revalidate value is set in the Cache-Control header.
        Returns:
        true if proxy-revalidate is set, false otherwise.
      • isPublic

        public boolean isPublic()
        Returns whether the public value is set in the Cache-Control header.
        Returns:
        true if public is set, false otherwise.
      • 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:
        getStaleIfError in interface CacheControl
        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:
        toString in class java.lang.Object