|
16 | 16 | package org.grails.web.servlet.view; |
17 | 17 |
|
18 | 18 | import grails.util.CacheEntry; |
| 19 | +import grails.util.GrailsStringUtils; |
19 | 20 | import grails.util.GrailsUtil; |
20 | 21 | import groovy.lang.GroovyObject; |
21 | 22 |
|
|
26 | 27 |
|
27 | 28 | import javax.servlet.http.HttpServletRequest; |
28 | 29 |
|
29 | | -import org.apache.commons.logging.Log; |
30 | | -import org.apache.commons.logging.LogFactory; |
| 30 | + |
31 | 31 | import org.grails.gsp.GroovyPagesTemplateEngine; |
32 | 32 | import org.grails.web.gsp.io.GrailsConventionGroovyPageLocator; |
33 | 33 | import org.grails.gsp.io.GroovyPageScriptSource; |
34 | 34 | import org.grails.web.servlet.mvc.GrailsWebRequest; |
35 | | -import org.grails.web.util.WebUtils; |
36 | 35 | import org.slf4j.Logger; |
37 | 36 | import org.slf4j.LoggerFactory; |
38 | 37 | import org.springframework.beans.factory.annotation.Autowired; |
@@ -96,7 +95,7 @@ protected View loadView(String viewName, Locale locale) throws Exception { |
96 | 95 |
|
97 | 96 | String viewCacheKey = groovyPageLocator.resolveViewFormat(viewName); |
98 | 97 |
|
99 | | - String currentControllerKeyPrefix = resolveCurrentControllerKeyPrefixes(); |
| 98 | + String currentControllerKeyPrefix = resolveCurrentControllerKeyPrefixes(viewName.startsWith("/")); |
100 | 99 | if (currentControllerKeyPrefix != null) { |
101 | 100 | viewCacheKey = currentControllerKeyPrefix + ':' + viewCacheKey; |
102 | 101 | } |
@@ -139,14 +138,25 @@ public View call() throws Exception { |
139 | 138 | /** |
140 | 139 | * @return prefix for cache key that contains current controller's context (currently plugin and namespace) |
141 | 140 | */ |
142 | | - protected String resolveCurrentControllerKeyPrefixes() { |
| 141 | + protected String resolveCurrentControllerKeyPrefixes(boolean absolute) { |
143 | 142 | String pluginContextPath; |
144 | 143 | String namespace; |
| 144 | + String controller; |
145 | 145 | GrailsWebRequest webRequest = GrailsWebRequest.lookup(); |
146 | 146 | if(webRequest != null) { |
| 147 | + StringBuilder stringBuilder = new StringBuilder(); |
147 | 148 | namespace = webRequest.getControllerNamespace(); |
| 149 | + controller = webRequest.getControllerName(); |
148 | 150 | pluginContextPath = (webRequest.getAttributes() != null && webRequest.getCurrentRequest() != null) ? webRequest.getAttributes().getPluginContextPath(webRequest.getCurrentRequest()) : null; |
149 | | - return (pluginContextPath != null ? pluginContextPath : "-") + "," + (namespace != null ? namespace : "-"); |
| 151 | + |
| 152 | + stringBuilder.append(GrailsStringUtils.isNotEmpty(pluginContextPath) ? pluginContextPath : "-"); |
| 153 | + stringBuilder.append(','); |
| 154 | + stringBuilder.append(GrailsStringUtils.isNotEmpty(namespace) ? namespace : "-"); |
| 155 | + if (!absolute && GrailsStringUtils.isNotEmpty(controller)) { |
| 156 | + stringBuilder.append(','); |
| 157 | + stringBuilder.append(controller); |
| 158 | + } |
| 159 | + return stringBuilder.toString(); |
150 | 160 | } else { |
151 | 161 | return null; |
152 | 162 | } |
|
0 commit comments