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

      @Nonnull public 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

      @Nonnull public 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

      @Nonnull public 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

      @Nonnull public 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

      @Nonnull public 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()
    • getMaxAgeSeconds

      @Nullable public Long getMaxAgeSeconds()
    • setSharedMaxAge

      @Nonnull public 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

      @Nonnull public 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

      @Nonnull public 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

      @Nonnull public 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

      @Nonnull public 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()
    • getSharedMaxAgeSeconds

      @Nullable public Long getSharedMaxAgeSeconds()
    • setPublic

      @Nonnull public 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()
    • setPrivate

      @Nonnull public 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()
    • setNoCache

      @Nonnull public 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()
    • setNoStore

      @Nonnull public 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()
    • setNoTransform

      @Nonnull public 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()
    • setMustRevalidate

      @Nonnull public 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()
    • setProxyRevalidate

      @Nonnull public 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()
    • addExtension

      @Nonnull public CacheControlBuilder addExtension(@Nonnull @Nonempty String sExtension)
    • getAllExtensions

      @Nonnull @ReturnsMutableCopy public com.helger.collection.commons.ICommonsList<String> getAllExtensions()
    • getAsHTTPHeaderValue

      @Nonnull public String getAsHTTPHeaderValue()
    • getClone

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

      public String toString()
      Overrides:
      toString in class Object