Cache settings may be configured for specific URLs via path pattern with
addCacheMapping(CacheControl, String. and
setCacheMappings(Properties), along with a fallback on default
settings for all URLs via setCacheControl(CacheControl).
Pattern matching can be done with PathMatcher or with parsed
PathPatterns. The syntax is largely the same with the latter being
more tailored for web usage and more efficient. The choice depends on the
presence of a resolved
String lookupPath or a parsed RequestPath which in turn depends on the
HandlerMapping that matched the current request.
All the settings supported by this interceptor can also be set on
AbstractController. This interceptor is mainly intended for applying
checks and preparations to a set of controllers mapped by a HandlerMapping.
PathMatcher, AntPathMatcher
| Modifier and Type | Field and Description |
|---|---|
| private final Map | |
| private final Map | |
| private static PathMatcher | |
| private PathMatcher | |
| private final PathPatternParser |
| Access | Constructor and Description |
|---|---|
| public | |
| public | WebContentInterceptor(PathPatternParser parser)
Constructor with a |
| Modifier and Type | Method and Description |
|---|---|
| public void | addCacheMapping(CacheControl
the cacheControl, String... CacheControl to usethe URL paths that will map to the given paths)CacheControlMap specific URL paths to a specific |
| public void | afterCompletion(HttpServletRequest
current HTTP request request, HttpServletResponse current HTTP response response, Object the handler (or handler, Exception HandlerMethod) that started asynchronous
execution, for type and/or instance examinationany exception thrown on handler execution, if any; this does not
include exceptions that have been handled through an exception resolver ex)Overrides default org. This implementation is empty. |
| protected CacheControl | Returns: the matchedCacheControl, or null if no matchthe path to match to path)Find a |
| protected CacheControl | Returns: the matchedCacheControl, or null if no matchthe path to match to lookupPath)Find a |
| protected Integer | Returns: the matched cacheSeconds, ornull if there is no matchthe path to match to path)Find a cacheSeconds value for the given parsed |
| protected Integer | Returns: the matched cacheSeconds, ornull if there is no matchthe path to match to lookupPath)Find a cacheSeconds instance for the given String lookupPath. |
| public void | postHandle(HttpServletRequest
current HTTP request request, HttpServletResponse current HTTP response response, Object the handler (or handler, ModelAndView HandlerMethod) that started asynchronous
execution, for type and/or instance examinationthe modelAndView)ModelAndView that the handler returned
(can also be null)Overrides default org. This implementation is empty. |
| public boolean | preHandle(HttpServletRequest
current HTTP request request, HttpServletResponse current HTTP response response, Object chosen handler to execute, for type and/or instance evaluation handler)Overrides default org. Interception point before the execution of a handler. |
| public void | setAlwaysUseFullPath(boolean alwaysUseFullPath)
Deprecated
as of 5.3, the path is resolved externally and obtained with
ServletRequestPathUtils#getCachedPathValue(ServletRequest)
Shortcut to the
|
| public void | setCacheMappings(Properties
a mapping between URL paths (as keys) and
cache seconds (as values, need to be integer-parsable) cacheMappings)Map settings for cache seconds to specific URL paths via patterns. |
| public void | setPathMatcher(PathMatcher pathMatcher)
Configure the PathMatcher to use to match URL paths against registered URL patterns to select the cache settings for a request. |
| public void | setUrlDecode(boolean urlDecode)
Deprecated
as of 5.3, the path is resolved externally and obtained with
ServletRequestPathUtils#getCachedPathValue(ServletRequest)
Shortcut to the
|
| public void | setUrlPathHelper(UrlPathHelper urlPathHelper)
Deprecated
as of 5.3, the path is resolved externally and obtained with
ServletRequestPathUtils#getCachedPathValue(ServletRequest)
Set the UrlPathHelper to use for resolution of lookup paths. |
| cacheControlMappings | back to summary |
|---|---|
| private final Map<PathPattern, CacheControl> cacheControlMappings | |
| cacheMappings | back to summary |
|---|---|
| private final Map<PathPattern, Integer> cacheMappings | |
| defaultPathMatcher | back to summary |
|---|---|
| private static PathMatcher defaultPathMatcher | |
| pathMatcher | back to summary |
|---|---|
| private PathMatcher pathMatcher | |
| patternParser | back to summary |
|---|---|
| private final PathPatternParser patternParser | |
| WebContentInterceptor | back to summary |
|---|---|
| public WebContentInterceptor() Default constructor with | |
| WebContentInterceptor | back to summary |
|---|---|
| public WebContentInterceptor(PathPatternParser parser) Constructor with a
| |
| addCacheMapping | back to summary |
|---|---|
| public void addCacheMapping(CacheControl cacheControl, String... paths) Map specific URL paths to a specific Overrides the default cache seconds setting of this interceptor.
Can specify an empty For pattern syntax see Note Path patterns are not supposed to overlap. If a request
matches several mappings, it is effectively undefined which one will apply
(due to the lack of key ordering in the underlying
| |
| lookupCacheControl | back to summary |
|---|---|
| protected CacheControl lookupCacheControl(PathContainer path) Find a
| |
| lookupCacheControl | back to summary |
|---|---|
| protected CacheControl lookupCacheControl(String lookupPath) Find a
| |
| lookupCacheSeconds | back to summary |
|---|---|
| protected Integer lookupCacheSeconds(PathContainer path) Find a cacheSeconds value for the given parsed
| |
| lookupCacheSeconds | back to summary |
|---|---|
| protected Integer lookupCacheSeconds(String lookupPath) Find a cacheSeconds instance for the given String lookupPath.
This is used when the | |
| preHandle | back to summary |
|---|---|
| public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException Overrides default org. Doc from org. Interception point before the execution of a handler. Called after HandlerMapping determined an appropriate handler object, but before HandlerAdapter invokes the handler. DispatcherServlet processes a handler in an execution chain, consisting of any number of interceptors, with the handler itself at the end. With this method, each interceptor can decide to abort the execution chain, typically sending an HTTP error or writing a custom response. Note special considerations apply for asynchronous
request processing. For more details see
The default implementation returns
| |
| setAlwaysUseFullPath | back to summary |
|---|---|
| public void setAlwaysUseFullPath(boolean alwaysUseFullPath)
Deprecated as of 5.3, the path is resolved externally and obtained with
Shortcut to the
| |
| setCacheMappings | back to summary |
|---|---|
| public void setCacheMappings(Properties cacheMappings) Map settings for cache seconds to specific URL paths via patterns. Overrides the default cache seconds setting of this interceptor. Can specify "-1" to exclude a URL path from default caching. For pattern syntax see Note Path patterns are not supposed to overlap. If a request
matches several mappings, it is effectively undefined which one will apply
(due to the lack of key ordering in
| |
| setPathMatcher | back to summary |
|---|---|
| public void setPathMatcher(PathMatcher pathMatcher) Configure the PathMatcher to use to match URL paths against registered URL patterns to select the cache settings for a request. This is an advanced property that should be used only when a
customized By default this is Note Setting | |
| setUrlDecode | back to summary |
|---|---|
| public void setUrlDecode(boolean urlDecode)
Deprecated as of 5.3, the path is resolved externally and obtained with
Shortcut to the
| |
| setUrlPathHelper | back to summary |
|---|---|
| public void setUrlPathHelper(UrlPathHelper urlPathHelper)
Deprecated as of 5.3, the path is resolved externally and obtained with
Set the UrlPathHelper to use for resolution of lookup paths.
| |