Package com.helger.http.cache
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 Summary
ConstructorsConstructorDescriptionConstructorCacheControlBuilder(@NonNull CacheControlBuilder aBase) Copy constructor -
Method Summary
Modifier and TypeMethodDescription@NonNull CacheControlBuilderaddExtension(@NonNull @Nonempty String sExtension) Add a custom cache-control extension directive.@NonNull com.helger.collection.commons.ICommonsList<String> @NonNull String@NonNull CacheControlBuildergetClone()@Nullable Long@Nullable LongbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanisPublic()@NonNull CacheControlBuilderSet the maximum age relative to the request time@NonNull CacheControlBuildersetMaxAgeDays(long nDays) Set the maximum age in days relative to the request time@NonNull CacheControlBuildersetMaxAgeHours(long nHours) Set the maximum age in hours relative to the request time@NonNull CacheControlBuildersetMaxAgeMinutes(long nMinutes) Set the maximum age in minutes relative to the request time@NonNull CacheControlBuildersetMaxAgeSeconds(long nSeconds) Set the maximum age in seconds relative to the request time.@NonNull CacheControlBuildersetMustRevalidate(boolean bMustRevalidate) Set the must-revalidate value.@NonNull CacheControlBuildersetNoCache(boolean bNoCache) Set the no-cache value.@NonNull CacheControlBuildersetNoStore(boolean bNoStore) Set the no-store value.@NonNull CacheControlBuildersetNoTransform(boolean bNoTransform) Set the no-transform value.@NonNull CacheControlBuildersetPrivate(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.@NonNull CacheControlBuildersetProxyRevalidate(boolean bProxyRevalidate) Set the proxy-revalidate value.@NonNull CacheControlBuildersetPublic(boolean bPublic) Set the public value. marks authenticated responses as cacheable; normally, if HTTP authentication is required, responses are automatically private.@NonNull CacheControlBuildersetSharedMaxAge(@NonNull TimeUnit eTimeUnit, long nDuration) Set the maximum age for shared caches relative to the request time.@NonNull CacheControlBuildersetSharedMaxAgeDays(long nDays) Set the maximum age for shared caches in days relative to the request time.@NonNull CacheControlBuildersetSharedMaxAgeHours(long nHours) Set the maximum age for shared caches in hours relative to the request time.@NonNull CacheControlBuildersetSharedMaxAgeMinutes(long nMinutes) Set the maximum age for shared caches in minutes relative to the request time.@NonNull CacheControlBuildersetSharedMaxAgeSeconds(long nSeconds) Set the maximum age for shared caches in seconds relative to the request time.toString()
-
Constructor Details
-
CacheControlBuilder
public CacheControlBuilder()Constructor -
CacheControlBuilder
Copy constructor- Parameters:
aBase- The object to copy the settings from. May not benull.
-
-
Method Details
-
setMaxAge
Set the maximum age relative to the request time- Parameters:
eTimeUnit-TimeUnitto usenDuration- The duration in the passed unit- Returns:
- this
-
setMaxAgeDays
Set the maximum age in days relative to the request time- Parameters:
nDays- Days to keep it- Returns:
- this
-
setMaxAgeHours
Set the maximum age in hours relative to the request time- Parameters:
nHours- Hours to keep it- Returns:
- this
-
setMaxAgeMinutes
Set the maximum age in minutes relative to the request time- Parameters:
nMinutes- Minutes to keep it- Returns:
- this
-
setMaxAgeSeconds
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:
trueif a max-age value has been set,falseotherwise.
-
getMaxAgeSeconds
- Returns:
- The max-age value in seconds, or
nullif not set.
-
setPublic
Set the public value. marks authenticated responses as cacheable; normally, if HTTP authentication is required, responses are automatically private.- Parameters:
bPublic-trueto enable public- Returns:
- this
-
isPublic
public boolean isPublic()- Returns:
trueif the public directive is enabled,falseotherwise.
-
setPrivate
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-trueto enable private- Returns:
- this
-
isPrivate
public boolean isPrivate()- Returns:
trueif the private directive is enabled,falseotherwise.
-
setNoCache
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-trueto enable no-cache- Returns:
- this
-
isNoCache
public boolean isNoCache()- Returns:
trueif the no-cache directive is enabled,falseotherwise.
-
setNoStore
Set the no-store value. Instructs caches not to keep a copy of the representation under any conditions.- Parameters:
bNoStore-trueto enable no-store- Returns:
- this
-
isNoStore
public boolean isNoStore()- Returns:
trueif the no-store directive is enabled,falseotherwise.
-
setNoTransform
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-trueto enable no-transform- Returns:
- this
-
isNoTransform
public boolean isNoTransform()- Returns:
trueif the no-transform directive is enabled,falseotherwise.
-
setMustRevalidate
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-trueto enable must-revalidate- Returns:
- this
-
isMustRevalidate
public boolean isMustRevalidate()- Returns:
trueif the must-revalidate directive is enabled,falseotherwise.
-
setProxyRevalidate
Set the proxy-revalidate value. Similar to must-revalidate, except that it only applies to proxy caches.- Parameters:
bProxyRevalidate-trueto enable proxy-revalidate- Returns:
- this
-
isProxyRevalidate
public boolean isProxyRevalidate()- Returns:
trueif the proxy-revalidate directive is enabled,falseotherwise.
-
addExtension
Add a custom cache-control extension directive.- Parameters:
sExtension- The extension string to add. May neither benullnor 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
- Returns:
- The Cache-Control header value string built from all configured
directives. Never
null.
-
getClone
- Specified by:
getClonein interfacecom.helger.base.clone.ICloneable<CacheControlBuilder>
-
toString
-