/** * Provides functionality to clear the cache for a certain view. * <p>This can be handy in case developer are able to modify views * (e.g. FreeMarker templates) at runtime after which you'd need to * clear the cache for the specified view. * @param viewName the view name for which the cached view object * (if any) needs to be removed * @param locale the locale for which the view object should be removed */ public void removeFromCache(String viewName, Locale locale) { if (!isCache()) { logger.warn("Caching is OFF (removal not necessary)"); } else { Object cacheKey = getCacheKey(viewName, locale); Object cachedView; synchronized (this.viewCreationCache) { this.viewAccessCache.remove(cacheKey); cachedView = this.viewCreationCache.remove(cacheKey); } if (logger.isDebugEnabled()) { // Some debug output might be useful... logger.debug(formatKey(cacheKey) + (cachedView != null ? "cleared from cache" : "not found in the cache")); } } }
@Override @Nullable public View resolveViewName(String viewName, Locale locale) throws Exception { if (!isCache()) { return createView(viewName, locale);
/** * Provides functionality to clear the cache for a certain view. * <p>This can be handy in case developer are able to modify views * (e.g. FreeMarker templates) at runtime after which you'd need to * clear the cache for the specified view. * @param viewName the view name for which the cached view object * (if any) needs to be removed * @param locale the locale for which the view object should be removed */ public void removeFromCache(String viewName, Locale locale) { if (!isCache()) { logger.warn("Caching is OFF (removal not necessary)"); } else { Object cacheKey = getCacheKey(viewName, locale); Object cachedView; synchronized (this.viewCreationCache) { this.viewAccessCache.remove(cacheKey); cachedView = this.viewCreationCache.remove(cacheKey); } if (logger.isDebugEnabled()) { // Some debug output might be useful... logger.debug(formatKey(cacheKey) + (cachedView != null ? "cleared from cache" : "not found in the cache")); } } }
@Override @Nullable public View resolveViewName(String viewName, Locale locale) throws Exception { if (!isCache()) { return createView(viewName, locale);
@Override public View resolveViewName(String viewName, Locale locale) throws Exception { if (!isCache()) { return createView(viewName, locale); } else { Object cacheKey = getCacheKey(viewName, locale); View view = this.viewAccessCache.get(cacheKey); if (view == null) { synchronized (this.viewCreationCache) { view = this.viewCreationCache.get(cacheKey); if (view == null) { // Ask the subclass to create the View object. view = createView(viewName, locale); if (view == null && this.cacheUnresolved) { view = UNRESOLVED_VIEW; } if (view != null) { this.viewAccessCache.put(cacheKey, view); this.viewCreationCache.put(cacheKey, view); if (logger.isTraceEnabled()) { logger.trace("Cached view [" + cacheKey + "]"); } } } } } return (view != UNRESOLVED_VIEW ? view : null); } }