Class CacheControlBuilder

java.lang.Object
com.helger.http.cache.CacheControlBuilder
All Implemented Interfaces:
com.helger.base.clone.ICloneable<CacheControlBuilder>

@NotThreadSafe public class CacheControlBuilder extends Object implements com.helger.base.clone.ICloneable<CacheControlBuilder>
This class is used to build the response HTTP header field Cache-Control value in a structured way. This header field is only applicable for HTTP/1.1
Author:
Philip Helger
  • Constructor Details

    • CacheControlBuilder

      public CacheControlBuilder()
      Constructor
    • CacheControlBuilder

      public CacheControlBuilder(@NonNull CacheControlBuilder aBase)
      Copy constructor
      Parameters:
      aBase - The object to copy the settings from. May not be null.
  • Method Details

    • setMaxAge

      public @NonNull CacheControlBuilder setMaxAge(@NonNull TimeUnit eTimeUnit, long nDuration)
      Set the maximum age relative to the request time
      Parameters:
      eTimeUnit - TimeUnit to use
      nDuration - The duration in the passed unit
      Returns:
      this
    • setMaxAgeDays

      public @NonNull CacheControlBuilder setMaxAgeDays(@Nonnegative long nDays)
      Set the maximum age in days relative to the request time
      Parameters:
      nDays - Days to keep it
      Returns:
      this
    • setMaxAgeHours

      public @NonNull CacheControlBuilder setMaxAgeHours(@Nonnegative long nHours)
      Set the maximum age in hours relative to the request time
      Parameters:
      nHours - Hours to keep it
      Returns:
      this
    • setMaxAgeMinutes

      public @NonNull CacheControlBuilder setMaxAgeMinutes(@Nonnegative long nMinutes)
      Set the maximum age in minutes relative to the request time
      Parameters:
      nMinutes - Minutes to keep it
      Returns:
      this
    • setMaxAgeSeconds

      public @NonNull CacheControlBuilder setMaxAgeSeconds(@Nonnegative long nSeconds)
      Set the maximum age in seconds relative to the request time. Specifies the maximum amount of time that a representation will be considered fresh. Similar to Expires, this directive is relative to the time of the request, rather than absolute. [seconds] is the number of seconds from the time of the request you wish the representation to be fresh for.
      Parameters:
      nSeconds - Seconds to keep it
      Returns:
      this
    • hasMaxAgeSeconds

      public boolean hasMaxAgeSeconds()
      Returns:
      true if a max-age value has been set, false otherwise.
    • getMaxAgeSeconds

      public @Nullable Long getMaxAgeSeconds()
      Returns:
      The max-age value in seconds, or null if not set.
    • setSharedMaxAge

      public @NonNull CacheControlBuilder setSharedMaxAge(@NonNull TimeUnit eTimeUnit, long nDuration)
      Set the maximum age for shared caches relative to the request time. Similar to max-age, except that it only applies to shared (e.g., proxy) caches.
      Parameters:
      eTimeUnit - TimeUnit to use
      nDuration - The duration in the passed unit
      Returns:
      this
    • setSharedMaxAgeDays

      public @NonNull CacheControlBuilder setSharedMaxAgeDays(@Nonnegative long nDays)
      Set the maximum age for shared caches in days relative to the request time. Similar to max-age, except that it only applies to shared (e.g., proxy) caches.
      Parameters:
      nDays - Days to keep it
      Returns:
      this
    • setSharedMaxAgeHours

      public @NonNull CacheControlBuilder setSharedMaxAgeHours(@Nonnegative long nHours)
      Set the maximum age for shared caches in hours relative to the request time. Similar to max-age, except that it only applies to shared (e.g., proxy) caches.
      Parameters:
      nHours - Hours to keep it
      Returns:
      this
    • setSharedMaxAgeMinutes

      public @NonNull CacheControlBuilder setSharedMaxAgeMinutes(@Nonnegative long nMinutes)
      Set the maximum age for shared caches in minutes relative to the request time. Similar to max-age, except that it only applies to shared (e.g., proxy) caches.
      Parameters:
      nMinutes - Minutes to keep it
      Returns:
      this
    • setSharedMaxAgeSeconds

      public @NonNull CacheControlBuilder setSharedMaxAgeSeconds(@Nonnegative long nSeconds)
      Set the maximum age for shared caches in seconds relative to the request time. Similar to max-age, except that it only applies to shared (e.g., proxy) caches.
      Parameters:
      nSeconds - Seconds to keep it
      Returns:
      this
    • hasSharedMaxAgeSeconds

      public boolean hasSharedMaxAgeSeconds()
      Returns:
      true if a shared max-age value has been set, false otherwise.
    • getSharedMaxAgeSeconds

      public @Nullable Long getSharedMaxAgeSeconds()
      Returns:
      The shared max-age value in seconds, or null if not set.
    • setPublic

      public @NonNull CacheControlBuilder setPublic(boolean bPublic)
      Set the public value. marks authenticated responses as cacheable; normally, if HTTP authentication is required, responses are automatically private.
      Parameters:
      bPublic - true to enable public
      Returns:
      this
    • isPublic

      public boolean isPublic()
      Returns:
      true if the public directive is enabled, false otherwise.
    • setPrivate

      public @NonNull CacheControlBuilder setPrivate(boolean bPrivate)
      Set the private value. allows caches that are specific to one user (e.g., in a browser) to store the response; shared caches (e.g., in a proxy) may not.
      Parameters:
      bPrivate - true to enable private
      Returns:
      this
    • isPrivate

      public boolean isPrivate()
      Returns:
      true if the private directive is enabled, false otherwise.
    • setNoCache

      public @NonNull CacheControlBuilder setNoCache(boolean bNoCache)
      Set the no-cache value. Forces caches to submit the request to the origin server for validation before releasing a cached copy, every time. This is useful to assure that authentication is respected (in combination with public), or to maintain rigid freshness, without sacrificing all of the benefits of caching.
      Parameters:
      bNoCache - true to enable no-cache
      Returns:
      this
    • isNoCache

      public boolean isNoCache()
      Returns:
      true if the no-cache directive is enabled, false otherwise.
    • setNoStore

      public @NonNull CacheControlBuilder setNoStore(boolean bNoStore)
      Set the no-store value. Instructs caches not to keep a copy of the representation under any conditions.
      Parameters:
      bNoStore - true to enable no-store
      Returns:
      this
    • isNoStore

      public boolean isNoStore()
      Returns:
      true if the no-store directive is enabled, false otherwise.
    • setNoTransform

      public @NonNull CacheControlBuilder setNoTransform(boolean bNoTransform)
      Set the no-transform value. Implementors of intermediate caches (proxies) have found it useful to convert the media type of certain entity bodies. A non- transparent proxy might, for example, convert between image formats in order to save cache space or to reduce the amount of traffic on a slow link. If a message includes the no-transform directive, an intermediate cache or proxy MUST NOT change those headers that are listed in section 13.5.2 as being subject to the no-transform directive. This implies that the cache or proxy MUST NOT change any aspect of the entity-body that is specified by these headers, including the value of the entity-body itself.
      Parameters:
      bNoTransform - true to enable no-transform
      Returns:
      this
    • isNoTransform

      public boolean isNoTransform()
      Returns:
      true if the no-transform directive is enabled, false otherwise.
    • setMustRevalidate

      public @NonNull CacheControlBuilder setMustRevalidate(boolean bMustRevalidate)
      Set the must-revalidate value. Tells caches that they must obey any freshness information you give them about a representation. HTTP allows caches to serve stale representations under special conditions; by specifying this header, you’re telling the cache that you want it to strictly follow your rules.
      Parameters:
      bMustRevalidate - true to enable must-revalidate
      Returns:
      this
    • isMustRevalidate

      public boolean isMustRevalidate()
      Returns:
      true if the must-revalidate directive is enabled, false otherwise.
    • setProxyRevalidate

      public @NonNull CacheControlBuilder setProxyRevalidate(boolean bProxyRevalidate)
      Set the proxy-revalidate value. Similar to must-revalidate, except that it only applies to proxy caches.
      Parameters:
      bProxyRevalidate - true to enable proxy-revalidate
      Returns:
      this
    • isProxyRevalidate

      public boolean isProxyRevalidate()
      Returns:
      true if the proxy-revalidate directive is enabled, false otherwise.
    • addExtension

      public @NonNull CacheControlBuilder addExtension(@Nonempty @NonNull @Nonempty String sExtension)
      Add a custom cache-control extension directive.
      Parameters:
      sExtension - The extension string to add. May neither be null nor empty and must not contain a comma.
      Returns:
      this for chaining
    • getAllExtensions

      @ReturnsMutableCopy public @NonNull com.helger.collection.commons.ICommonsList<String> getAllExtensions()
      Returns:
      A mutable copy of all extension directives. Never null.
    • getAsHTTPHeaderValue

      public @NonNull String getAsHTTPHeaderValue()
      Returns:
      The Cache-Control header value string built from all configured directives. Never null.
    • getClone

      public @NonNull CacheControlBuilder getClone()
      Specified by:
      getClone in interface com.helger.base.clone.ICloneable<CacheControlBuilder>
    • toString

      public String toString()
      Overrides:
      toString in class Object