Package io.wcm.wcm.commons.caching
Class CacheHeader
java.lang.Object
io.wcm.wcm.commons.caching.CacheHeader
Contains common functionality to control client-side caching.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisNotModified(@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 booleanisNotModified(@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 booleanisNotModified(@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 booleanisNotModified(@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 voidsetExpires(@NotNull javax.servlet.http.HttpServletResponse response, @Nullable Date date) Set expires header to given date.static voidsetExpiresDays(@NotNull javax.servlet.http.HttpServletResponse response, int days) Set expires header to given amount of days in the future.static voidsetExpiresHours(@NotNull javax.servlet.http.HttpServletResponse response, int hours) Set expires header to given amount of hours in the future.static voidsetExpiresSeconds(@NotNull javax.servlet.http.HttpServletResponse response, int seconds) Set expires header to given amount of seconds in the future.static voidsetNonCachingHeaders(@NotNull javax.servlet.http.HttpServletResponse response) Set headers to disallow caching in browser, proxy servers and dispatcher for the current response.
-
Method Details
-
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 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
-