Package io.wcm.wcm.commons.caching
Class CacheHeader
- java.lang.Object
-
- io.wcm.wcm.commons.caching.CacheHeader
-
@ProviderType public final class CacheHeader extends java.lang.Object
Contains common functionality to control client-side caching.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isNotModified(@NotNull ModificationDateProvider dateProvider, @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.SlingHttpServletResponse response)
Compares the "If-Modified-Since header" of the incoming request with the last modification date of an aggregated resource.static boolean
isNotModified(@NotNull ModificationDateProvider dateProvider, @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.SlingHttpServletResponse response, boolean setExpiresHeader)
Compares the "If-Modified-Since header" of the incoming request with the last modification date of an aggregated resource.static boolean
isNotModified(@NotNull org.apache.sling.api.resource.Resource resource, @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.SlingHttpServletResponse response)
Compares the "If-Modified-Since header" of the incoming request with the last modification date of a resource.static boolean
isNotModified(@NotNull org.apache.sling.api.resource.Resource resource, @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull org.apache.sling.api.SlingHttpServletResponse response, boolean setExpiresHeader)
Compares the "If-Modified-Since header" of the incoming request with the last modification date of a resource.static void
setExpires(@NotNull javax.servlet.http.HttpServletResponse response, @Nullable java.util.Date date)
Set expires header to given date.static void
setExpiresDays(@NotNull javax.servlet.http.HttpServletResponse response, int days)
Set expires header to given amount of days in the future.static void
setExpiresHours(@NotNull javax.servlet.http.HttpServletResponse response, int hours)
Set expires header to given amount of hours in the future.static void
setExpiresSeconds(@NotNull javax.servlet.http.HttpServletResponse response, int seconds)
Set expires header to given amount of seconds in the future.static void
setNonCachingHeaders(@NotNull javax.servlet.http.HttpServletResponse response)
Set headers to disallow caching in browser, proxy servers and dispatcher for the current response.
-
-
-
Method Detail
-
isNotModified
public static boolean isNotModified(@NotNull @NotNull org.apache.sling.api.resource.Resource resource, @NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull org.apache.sling.api.SlingHttpServletResponse response)
Compares the "If-Modified-Since header" of the incoming request with the last modification date of a resource. If the resource was not modified since the client retrieved the resource, a 304-redirect is send to the response (and the method returns true). If the resource has changed (or the client didn't) supply the "If-Modified-Since" header a "Last-Modified" header is set so future requests can be cached.Expires header is automatically set on author instance, and not set on publish instance.
- Parameters:
resource
- the JCR resource the last modification date is taken fromrequest
- Requestresponse
- Response- Returns:
- true if the method send a 304 redirect, so that the caller shouldn't write any output to the response stream
-
isNotModified
public static boolean isNotModified(@NotNull @NotNull org.apache.sling.api.resource.Resource resource, @NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull org.apache.sling.api.SlingHttpServletResponse response, boolean setExpiresHeader)
Compares the "If-Modified-Since header" of the incoming request with the last modification date of a resource. If the resource was not modified since the client retrieved the resource, a 304-redirect is send to the response (and the method returns true). If the resource has changed (or the client didn't) supply the "If-Modified-Since" header a "Last-Modified" header is set so future requests can be cached.- Parameters:
resource
- the JCR resource the last modification date is taken fromrequest
- Requestresponse
- ResponsesetExpiresHeader
- Set expires header to -1 to ensure the browser checks for a new version on every request.- Returns:
- true if the method send a 304 redirect, so that the caller shouldn't write any output to the response stream
-
isNotModified
public static boolean isNotModified(@NotNull @NotNull ModificationDateProvider dateProvider, @NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull org.apache.sling.api.SlingHttpServletResponse response)
Compares the "If-Modified-Since header" of the incoming request with the last modification date of an aggregated resource. If the resource was not modified since the client retrieved the resource, a 304-redirect is send to the response (and the method returns true). If the resource has changed (or the client didn't) supply the "If-Modified-Since" header a "Last-Modified" header is set so future requests can be cached.Expires header is automatically set on author instance, and not set on publish instance.
- Parameters:
dateProvider
- abstraction layer that calculates the last-modification time of an aggregated resourcerequest
- Requestresponse
- Response- Returns:
- true if the method send a 304 redirect, so that the caller shouldn't write any output to the response stream
-
isNotModified
public static boolean isNotModified(@NotNull @NotNull ModificationDateProvider dateProvider, @NotNull @NotNull org.apache.sling.api.SlingHttpServletRequest request, @NotNull @NotNull org.apache.sling.api.SlingHttpServletResponse response, boolean setExpiresHeader)
Compares the "If-Modified-Since header" of the incoming request with the last modification date of an aggregated resource. If the resource was not modified since the client retrieved the resource, a 304-redirect is send to the response (and the method returns true). If the resource has changed (or the client didn't) supply the "If-Modified-Since" header a "Last-Modified" header is set so future requests can be cached.- Parameters:
dateProvider
- abstraction layer that calculates the last-modification time of an aggregated resourcerequest
- Requestresponse
- ResponsesetExpiresHeader
- Set expires header to -1 to ensure the browser checks for a new version on every request.- Returns:
- true if the method send a 304 redirect, so that the caller shouldn't write any output to the response stream
-
setNonCachingHeaders
public static void setNonCachingHeaders(@NotNull @NotNull javax.servlet.http.HttpServletResponse response)
Set headers to disallow caching in browser, proxy servers and dispatcher for the current response.- Parameters:
response
- Current response
-
setExpires
public static void setExpires(@NotNull @NotNull javax.servlet.http.HttpServletResponse response, @Nullable @Nullable java.util.Date date)
Set expires header to given date.- Parameters:
response
- Responsedate
- Expires date
-
setExpiresSeconds
public static void setExpiresSeconds(@NotNull @NotNull javax.servlet.http.HttpServletResponse response, int seconds)
Set expires header to given amount of seconds in the future.- Parameters:
response
- Responseseconds
- Seconds to expire
-
setExpiresHours
public static void setExpiresHours(@NotNull @NotNull javax.servlet.http.HttpServletResponse response, int hours)
Set expires header to given amount of hours in the future.- Parameters:
response
- Responsehours
- Hours to expire
-
setExpiresDays
public static void setExpiresDays(@NotNull @NotNull javax.servlet.http.HttpServletResponse response, int days)
Set expires header to given amount of days in the future.- Parameters:
response
- Responsedays
- Days to expire
-
-