Class AbstractCachingViewResolver

          extended byorg.springframework.web.servlet.view.AbstractCachingViewResolver
All Implemented Interfaces:
ApplicationContextAware, ViewResolver
Direct Known Subclasses:
ResourceBundleViewResolver, UrlBasedViewResolver, XmlViewResolver

public abstract class AbstractCachingViewResolver
extends WebApplicationObjectSupport
implements ViewResolver

Convenient superclass for view resolvers. Caches views once resolved: This means that view resolution won't be a performance problem, no matter how costly initial view retrieval is.

View retrieval is deferred to subclasses via the loadView template method.

Rod Johnson, Juergen Hoeller
See Also:
loadView(java.lang.String, java.util.Locale)

Field Summary
Fields inherited from class
Constructor Summary
Method Summary
protected  java.lang.String getCacheKey(java.lang.String viewName, java.util.Locale locale)
          Return the cache key for the given viewName and the given locale.
 boolean isCache()
          Return if caching is enabled.
protected abstract  View loadView(java.lang.String viewName, java.util.Locale locale)
          Subclasses must implement this method.
 View resolveViewName(java.lang.String viewName, java.util.Locale locale)
          Resolve the given view by name.
 void setCache(boolean cache)
          Enable respectively disable caching.
Methods inherited from class
getServletContext, getTempDir, getWebApplicationContext, requiredContextClass
Methods inherited from class
getApplicationContext, getMessageSourceAccessor, initApplicationContext, setApplicationContext
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public AbstractCachingViewResolver()
Method Detail


public void setCache(boolean cache)
Enable respectively disable caching. Disable this only for debugging and development. Default is for caching to be enabled.

Warning: Disabling caching can severely impact performance. Tests indicate that turning caching off reduces performance by at least 20%. Increased object churn probably eventually makes the problem even worse.


public boolean isCache()
Return if caching is enabled.


public View resolveViewName(java.lang.String viewName,
                            java.util.Locale locale)
                     throws java.lang.Exception
Description copied from interface: ViewResolver
Resolve the given view by name.

Specified by:
resolveViewName in interface ViewResolver
viewName - name of the view to resolve
locale - Locale in which to resolve the view. ViewResolvers that support internationalization should respect this.
java.lang.Exception - if the view cannot be resolved


protected java.lang.String getCacheKey(java.lang.String viewName,
                                       java.util.Locale locale)
Return the cache key for the given viewName and the given locale. Needs to regard the locale in general, as a different locale can lead to a different view! Can be overridden in subclasses.


protected abstract View loadView(java.lang.String viewName,
                                 java.util.Locale locale)
                          throws java.lang.Exception
Subclasses must implement this method. There need be no concern for efficiency, as this class will cache views. Not all subclasses may support internationalization: A subclass that doesn't can simply ignore the locale parameter.

viewName - the name of the view to retrieve
locale - the Locale to retrieve the view for
the View instance
java.lang.Exception - if the view couldn't be resolved

Copyright (C) 2003-2004 The Spring Framework Project.