Class AbstractCachingViewResolver
- All Implemented Interfaces:
- Aware,- ApplicationContextAware,- ServletContextAware,- ViewResolver
- Direct Known Subclasses:
- ResourceBundleViewResolver,- UrlBasedViewResolver,- XmlViewResolver
ViewResolver
 implementations. Caches View objects
 once resolved: This means that view resolution won't be a performance problem,
 no matter how costly initial view retrieval is.
 Subclasses need to implement the loadView(java.lang.String, java.util.Locale) template method,
 building the View object for a specific view name and locale.
- Author:
- Rod Johnson, Juergen Hoeller
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic interfaceFilter that determines if view should be cached.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final intDefault maximum number of entries for the view cache: 1024.Fields inherited from class org.springframework.context.support.ApplicationObjectSupportlogger
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidClear the entire view cache, removing all cached view objects.protected ViewcreateView(String viewName, Locale locale) Create the actual View object.Return filter function that determines if view should be cached.protected ObjectgetCacheKey(String viewName, Locale locale) Return the cache key for the given view name and the given locale.intReturn the maximum number of entries for the view cache.booleanisCache()Return if caching is enabled.booleanReturn if caching of unresolved views is enabled.protected abstract ViewSubclasses must implement this method, building a View object for the specified view.voidremoveFromCache(String viewName, Locale locale) Provides functionality to clear the cache for a certain view.resolveViewName(String viewName, Locale locale) Resolve the given view by name.voidsetCache(boolean cache) Enable or disable caching.voidsetCacheFilter(AbstractCachingViewResolver.CacheFilter cacheFilter) Set the filter that determines if view should be cached.voidsetCacheLimit(int cacheLimit) Specify the maximum number of entries for the view cache.voidsetCacheUnresolved(boolean cacheUnresolved) Whether a view name once resolved tonullshould be cached and automatically resolved tonullsubsequently.Methods inherited from class org.springframework.web.context.support.WebApplicationObjectSupportgetServletContext, getTempDir, getWebApplicationContext, initApplicationContext, initServletContext, isContextRequired, setServletContextMethods inherited from class org.springframework.context.support.ApplicationObjectSupportgetApplicationContext, getMessageSourceAccessor, initApplicationContext, obtainApplicationContext, requiredContextClass, setApplicationContext
- 
Field Details- 
DEFAULT_CACHE_LIMITpublic static final int DEFAULT_CACHE_LIMITDefault maximum number of entries for the view cache: 1024.- See Also:
 
 
- 
- 
Constructor Details- 
AbstractCachingViewResolverpublic AbstractCachingViewResolver()
 
- 
- 
Method Details- 
setCacheLimitpublic void setCacheLimit(int cacheLimit) Specify the maximum number of entries for the view cache. Default is 1024.
- 
getCacheLimitpublic int getCacheLimit()Return the maximum number of entries for the view cache.
- 
setCachepublic void setCache(boolean cache) Enable or disable caching.This is equivalent to setting the "cacheLimit"property to the default limit (1024) or to 0, respectively.Default is "true": caching is enabled. Disable this only for debugging and development. 
- 
isCachepublic boolean isCache()Return if caching is enabled.
- 
setCacheUnresolvedpublic void setCacheUnresolved(boolean cacheUnresolved) Whether a view name once resolved tonullshould be cached and automatically resolved tonullsubsequently.Default is "true": unresolved view names are cached. Note that this flag only applies if the general "cache"flag is kept at its default of "true" as well.Of specific interest is the ability for some AbstractUrlBasedViewimplementations (e.g., FreeMarker) to check if an underlying resource exists viaAbstractUrlBasedView.checkResource(Locale). With this flag set to "false", an underlying resource that re-appears is noticed and used. With the flag set to "true", only one check is made.
- 
isCacheUnresolvedpublic boolean isCacheUnresolved()Return if caching of unresolved views is enabled.
- 
setCacheFilterSet the filter that determines if view should be cached.Default behaviour is to cache all views. - Since:
- 5.2
 
- 
getCacheFilterReturn filter function that determines if view should be cached.- Since:
- 5.2
 
- 
resolveViewNameDescription copied from interface:ViewResolverResolve the given view by name.Note: To allow for ViewResolver chaining, a ViewResolver should return nullif a view with the given name is not defined in it. However, this is not required: Some ViewResolvers will always attempt to build View objects with the given name, unable to returnnull(rather throwing an exception when View creation failed).- Specified by:
- resolveViewNamein interface- ViewResolver
- Parameters:
- viewName- name of the view to resolve
- locale- the Locale in which to resolve the view. ViewResolvers that support internationalization should respect this.
- Returns:
- the View object, or nullif not found (optional, to allow for ViewResolver chaining)
- Throws:
- Exception- if the view cannot be resolved (typically in case of problems creating an actual View object)
 
- 
getCacheKeyReturn the cache key for the given view name and the given locale.Default is a String consisting of view name and locale suffix. Can be overridden in subclasses. Needs to respect the locale in general, as a different locale can lead to a different view resource. 
- 
removeFromCacheProvides functionality to clear the cache for a certain view.This can be handy in case developers are able to modify views (e.g., FreeMarker templates) at runtime after which you'd need to clear the cache for the specified view. - Parameters:
- viewName- the view name for which the cached view object (if any) needs to be removed
- locale- the locale for which the view object should be removed
 
- 
clearCachepublic void clearCache()Clear the entire view cache, removing all cached view objects. Subsequent resolve calls will lead to recreation of demanded view objects.
- 
createViewCreate the actual View object.The default implementation delegates to loadView(java.lang.String, java.util.Locale). This can be overridden to resolve certain view names in a special fashion, before delegating to the actualloadViewimplementation provided by the subclass.- Parameters:
- viewName- the name of the view to retrieve
- locale- the Locale to retrieve the view for
- Returns:
- the View instance, or nullif not found (optional, to allow for ViewResolver chaining)
- Throws:
- Exception- if the view couldn't be resolved
- See Also:
 
- 
loadViewSubclasses must implement this method, building a View object for the specified view. The returned View objects will be cached by this ViewResolver base class.Subclasses are not forced to support internationalization: A subclass that does not may simply ignore the locale parameter. - Parameters:
- viewName- the name of the view to retrieve
- locale- the Locale to retrieve the view for
- Returns:
- the View instance, or nullif not found (optional, to allow for ViewResolver chaining)
- Throws:
- Exception- if the view couldn't be resolved
- See Also:
 
 
-