Class CacheDirective

  • All Implemented Interfaces:
    NamedValue<java.lang.String>

    public final class CacheDirective
    extends java.lang.Object
    implements NamedValue<java.lang.String>
    Directive for caching mechanisms along the call chain. This overrides the default behavior of those caches and proxies.

    Note that when used with HTTP connectors, this class maps to the "Cache-Control" header.
    Author:
    Jerome Louvel
    • Constructor Detail

      • CacheDirective

        public CacheDirective​(java.lang.String name)
        Constructor for directives with no value.
        Parameters:
        name - The directive name.
      • CacheDirective

        public CacheDirective​(java.lang.String name,
                              java.lang.String value)
        Constructor for directives with a value.
        Parameters:
        name - The directive name.
        value - The directive value.
      • CacheDirective

        public CacheDirective​(java.lang.String name,
                              java.lang.String value,
                              boolean digit)
        Constructor for directives with a value.
        Parameters:
        name - The directive name.
        value - The directive value.
        digit - The kind of value (true for a digit value, false otherwise).
    • Method Detail

      • maxStale

        public static CacheDirective maxStale()
        Creates a "max-stale" directive. Indicates that the client is willing to accept a response that has exceeded its expiration time by any amount of time.

        Note that this directive can be used on requests only.
        Returns:
        A new "max-stale" directive.
        See Also:
        HTTP 1.1 - Modifications of the Basic Expiration Mechanism
      • maxStale

        public static CacheDirective maxStale​(int maxStale)
        Creates a "max-stale" directive. Indicates that the client is willing to accept a response that has exceeded its expiration time by a given amount of time.

        Note that this directive can be used on requests only.
        Parameters:
        maxStale - Maximum stale age in seconds.
        Returns:
        A new "max-stale" directive.
        See Also:
        HTTP 1.1 - Modifications of the Basic Expiration Mechanism
      • minFresh

        public static CacheDirective minFresh​(int minFresh)
        Creates a "min-fresh" directive. Indicates that the client is willing to accept a response whose freshness lifetime is no less than its current age plus the specified time in seconds. That is, the client wants a response that will still be fresh for at least the specified number of seconds.

        Note that this directive can be used on requests only.
        Parameters:
        minFresh - Minimum freshness lifetime in seconds.
        Returns:
        A new "min-fresh" directive.
        See Also:
        HTTP 1.1 - Modifications of the Basic Expiration Mechanism
      • mustRevalidate

        public static CacheDirective mustRevalidate()
        Creates a "must-revalidate" directive. Indicates that the origin server requires revalidation of a cache entry on any subsequent use.

        Note that this directive can be used on responses only.
        Returns:
        A new "must-revalidate" directive.
        See Also:
        HTTP 1.1 - Cache Revalidation and Reload Controls
      • noCache

        public static CacheDirective noCache()
        Creates a "no-cache" directive. Indicates that a cache must not use the response to satisfy subsequent requests without successful revalidation with the origin server.

        Note that this directive can be used on requests or responses.
        Returns:
        A new "no-cache" directive.
        See Also:
        HTTP 1.1 - What is Cacheable
      • noCache

        public static CacheDirective noCache​(java.util.List<java.lang.String> fieldNames)
        Creates a "no-cache" directive. Indicates that a cache must not use the response to satisfy subsequent requests without successful revalidation with the origin server.

        Note that this directive can be used on requests or responses.
        Parameters:
        fieldNames - Field names, typically a HTTP header name, that must not be sent by caches.
        Returns:
        A new "no-cache" directive.
        See Also:
        HTTP 1.1 - What is Cacheable
      • noCache

        public static CacheDirective noCache​(java.lang.String fieldName)
        Creates a "no-cache" directive. Indicates that a cache must not use the response to satisfy subsequent requests without successful revalidation with the origin server.

        Note that this directive can be used on requests or responses.
        Parameters:
        fieldName - A field name, typically a HTTP header name, that must not be sent by caches.
        Returns:
        A new "no-cache" directive.
        See Also:
        HTTP 1.1 - What is Cacheable
      • noStore

        public static CacheDirective noStore()
        Creates a "no-store" directive. Indicates that a cache must not release or retain any information about the call. This applies to both private and shared caches.

        Note that this directive can be used on requests or responses.
        Returns:
        A new "no-store" directive.
        See Also:
        HTTP 1.1 - What May be Stored by Caches
      • noTransform

        public static CacheDirective noTransform()
        Creates a "no-transform" directive. Indicates that a cache or intermediary proxy must not transform the response entity.

        Note that this directive can be used on requests or responses.
        Returns:
        A new "no-transform" directive.
        See Also:
        HTTP 1.1 - No-Transform Directive
      • onlyIfCached

        public static CacheDirective onlyIfCached()
        Creates a "onlyIfCached" directive. Indicates that only cached responses should be returned to the client.

        Note that this directive can be used on requests only.
        Returns:
        A new "only-if-cached" directive.
        See Also:
        HTTP 1.1 - Cache Revalidation and Reload Controls
      • privateInfo

        public static CacheDirective privateInfo()
        Creates a "private" directive. Indicates that all or part of the response message is intended for a single user and must not be cached by a shared cache.

        Note that this directive can be used on responses only.
        Returns:
        A new "private" directive.
        See Also:
        HTTP 1.1 - What is Cacheable
      • privateInfo

        public static CacheDirective privateInfo​(java.util.List<java.lang.String> fieldNames)
        Creates a "private" directive. Indicates that all or part of the response message is intended for a single user and must not be cached by a shared cache.

        Note that this directive can be used on responses only.
        Parameters:
        fieldNames - Field names, typically a HTTP header name, that must be private.
        Returns:
        A new "private" directive.
        See Also:
        HTTP 1.1 - What is Cacheable
      • privateInfo

        public static CacheDirective privateInfo​(java.lang.String fieldName)
        Creates a "private" directive. Indicates that all or part of the response message is intended for a single user and must not be cached by a shared cache.

        Note that this directive can be used on responses only.
        Parameters:
        fieldName - A field name, typically a HTTP header name, that is private.
        Returns:
        A new "private" directive.
        See Also:
        HTTP 1.1 - What is Cacheable
      • proxyMustRevalidate

        public static CacheDirective proxyMustRevalidate()
        Creates a "proxy-revalidate" directive. Indicates that the origin server requires revalidation of a cache entry on any subsequent use, except that it does not apply to non-shared user agent caches

        Note that this directive can be used on responses only.
        Returns:
        A new "proxy-revalidate" directive.
        See Also:
        HTTP 1.1 - Cache Revalidation and Reload Controls
      • publicInfo

        public static CacheDirective publicInfo()
        Creates a "public" directive. Indicates that the response may be cached by any cache, even if it would normally be non-cacheable or cacheable only within a non-shared cache.

        Note that this directive can be used on responses only.
        Returns:
        A new "public" directive.
        See Also:
        HTTP 1.1 - What is Cacheable
      • sharedMaxAge

        public static CacheDirective sharedMaxAge​(int sharedMaxAge)
        Creates a "s-maxage" directive. Indicates that the client is willing to accept a response from a shared cache (but not a private cache) whose age is no greater than the specified time in seconds.

        Note that this directive can be used on responses only.
        Parameters:
        sharedMaxAge - Maximum age in seconds.
        Returns:
        A new "s-maxage" directive.
        See Also:
        HTTP 1.1 - Modifications of the Basic Expiration Mechanism
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • getName

        public java.lang.String getName()
        Returns the name.
        Specified by:
        getName in interface NamedValue<java.lang.String>
        Returns:
        The name.
      • getValue

        public java.lang.String getValue()
        Returns the value.
        Specified by:
        getValue in interface NamedValue<java.lang.String>
        Returns:
        The value.
      • hashCode

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

        public boolean isDigit()
        Returns true if the directive contains a digit value.
        Returns:
        True if the directive contains a digit value.
      • setDigit

        public void setDigit​(boolean digit)
        Indicates if the directive is a digit value.
        Parameters:
        digit - True if the directive contains a digit value.
      • setName

        public void setName​(java.lang.String name)
        Sets the name.
        Parameters:
        name - The name.
      • setValue

        public void setValue​(java.lang.String value)
        Sets the value.
        Specified by:
        setValue in interface NamedValue<java.lang.String>
        Parameters:
        value - The value.
      • toString

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