org.springframework.web.servlet.ViewResolver
implementations. Caches org.springframework.web.servlet.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 template method,
building the View object for a specific view name and locale.
loadView
| Modifier and Type | Class and Description |
|---|---|
| public static interface | AbstractCachingViewResolver.
Filter that determines if view should be cached. |
| Modifier and Type | Field and Description |
|---|---|
| private AbstractCachingViewResolver. | cacheFilter
Filter function that determines if view should be cached. |
| private volatile int | cacheLimit
The maximum number of entries in the cache. |
| private boolean | cacheUnresolved
Whether we should refrain from resolving views again if unresolved once. |
| private static final AbstractCachingViewResolver. | DEFAULT_CACHE_FILTER
Default cache filter that always caches. |
| public static final int | DEFAULT_CACHE_LIMIT
Default maximum number of entries for the view cache: 1024. |
| private static final View | UNRESOLVED_VIEW
Dummy marker object for unresolved views in the cache Maps. |
| private final Map | viewAccessCache
Fast access cache for Views, returning already cached instances without a global lock. |
| private final Map | viewCreationCache
Map from view key to View instance, synchronized for View creation. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| protected View | Returns: the View instance, ornull if not found
(optional, to allow for ViewResolver chaining)the name of the view to retrieve viewName, Locale the Locale to retrieve the view for locale)Create the actual View object. |
| private static String | |
| public AbstractCachingViewResolver. | |
| protected Object | getCacheKey(String viewName, Locale locale)
Return the cache key for the given view name and the given locale. |
| public int | |
| public boolean | |
| public boolean | |
| protected abstract View | |
| public void | removeFromCache(String
the view name for which the cached view object
(if any) needs to be removed viewName, Locale the locale for which the view object should be removed locale)Provides functionality to clear the cache for a certain view. |
| public View | resolveViewName(String
name of the view to resolve viewName, Locale the Locale in which to resolve the view.
ViewResolvers that support internationalization should respect this. locale)Implements org. Resolve the given view by name. |
| public void | |
| public void | setCacheFilter(AbstractCachingViewResolver.
Set the filter that determines if view should be cached. |
| public void | |
| public void | setCacheUnresolved(boolean cacheUnresolved)
Whether a view name once resolved to |
| cacheFilter | back to summary |
|---|---|
| private AbstractCachingViewResolver. Filter function that determines if view should be cached. | |
| cacheLimit | back to summary |
|---|---|
| private volatile int cacheLimit The maximum number of entries in the cache. | |
| cacheUnresolved | back to summary |
|---|---|
| private boolean cacheUnresolved Whether we should refrain from resolving views again if unresolved once. | |
| DEFAULT_CACHE_FILTER | back to summary |
|---|---|
| private static final AbstractCachingViewResolver. Default cache filter that always caches. | |
| DEFAULT_CACHE_LIMIT | back to summary |
|---|---|
| public static final int DEFAULT_CACHE_LIMIT Default maximum number of entries for the view cache: 1024. | |
| UNRESOLVED_VIEW | back to summary |
|---|---|
| private static final View UNRESOLVED_VIEW Dummy marker object for unresolved views in the cache Maps. | |
| viewAccessCache | back to summary |
|---|---|
| private final Map<Object, View> viewAccessCache Fast access cache for Views, returning already cached instances without a global lock. | |
| viewCreationCache | back to summary |
|---|---|
| private final Map<Object, View> viewCreationCache Map from view key to View instance, synchronized for View creation.
| |
| AbstractCachingViewResolver | back to summary |
|---|---|
| public AbstractCachingViewResolver() | |
| clearCache | back to summary |
|---|---|
| public void clearCache() Clear the entire view cache, removing all cached view objects. Subsequent resolve calls will lead to recreation of demanded view objects. | |
| createView | back to summary |
|---|---|
| protected View createView(String viewName, Locale locale) throws Exception Create the actual View object. The default implementation delegates to | |
| formatKey | back to summary |
|---|---|
| private static String formatKey(Object cacheKey) | |
| getCacheFilter | back to summary |
|---|---|
| public AbstractCachingViewResolver. Return filter function that determines if view should be cached.
| |
| getCacheKey | back to summary |
|---|---|
| protected Object getCacheKey(String viewName, Locale locale) Return 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. | |
| getCacheLimit | back to summary |
|---|---|
| public int getCacheLimit() Return the maximum number of entries for the view cache. | |
| isCache | back to summary |
|---|---|
| public boolean isCache() Return if caching is enabled. | |
| isCacheUnresolved | back to summary |
|---|---|
| public boolean isCacheUnresolved() Return if caching of unresolved views is enabled. | |
| loadView | back to summary |
|---|---|
| protected abstract View loadView(String viewName, Locale locale) throws Exception Subclasses 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.
| |
| removeFromCache | back to summary |
|---|---|
| public void removeFromCache(String viewName, Locale locale) Provides 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. | |
| resolveViewName | back to summary |
|---|---|
| public View resolveViewName(String viewName, Locale locale) throws Exception Implements org. Doc from org. Resolve the given view by name. Note To allow for ViewResolver chaining, a ViewResolver should
return | |
| setCache | back to summary |
|---|---|
| public void setCache(boolean cache) Enable or disable caching. This is equivalent to setting the Default is "true": caching is enabled. Disable this only for debugging and development. | |
| setCacheFilter | back to summary |
|---|---|
| public void setCacheFilter(AbstractCachingViewResolver. Set the filter that determines if view should be cached. Default behaviour is to cache all views.
| |
| setCacheLimit | back to summary |
|---|---|
| public void setCacheLimit(int cacheLimit) Specify the maximum number of entries for the view cache. Default is 1024. | |
| setCacheUnresolved | back to summary |
|---|---|
| public void setCacheUnresolved(boolean cacheUnresolved) Whether a view name once resolved to Default is "true": unresolved view names are cached.
Note that this flag only applies if the general Of specific interest is the ability for some | |
| Modifier and Type | Method and Description |
|---|---|
| public boolean |
| filter | back to summary |
|---|---|
| public boolean filter(View view, String viewName, Locale locale) Indicates whether the given view should be cached. The name and locale used to resolve the view are also provided. | |