Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch '2.1.x' of github.com:grails/grails-core into 2.1.x

  • Loading branch information...
commit d92969c27bccefa831dd8456889d6ce7632394e8 2 parents c48d8e3 + 4a9752e
@graemerocher graemerocher authored
View
3  grails-core/build.gradle
@@ -8,6 +8,9 @@ dependencies {
exclude group: 'commons-logging', module:'commons-logging'
exclude group: 'commons-beanutils', module:'commons-beanutils'
}
+ compile( "com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:${concurrentlinkedhashmapVersion}" ) {
+ exclude group: 'commons-logging', module:'commons-logging'
+ }
compile("org.springframework:spring-aop:${springVersion}") {
exclude group: 'commons-logging', module:'commons-logging'
}
View
50 ...ls-core/src/main/groovy/org/codehaus/groovy/grails/commons/ControllerArtefactHandler.java
@@ -17,18 +17,31 @@
import grails.util.Environment;
-import java.util.concurrent.ConcurrentHashMap;
+import org.codehaus.groovy.grails.plugins.support.aware.GrailsApplicationAware;
+
+import com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap;
/**
+ * Lookup controllers for uris.
+ *
+ * <p>This class is responsible for looking up controller classes for uris.</p>
+ *
+ * <p>Lookups are cached in non-development mode, and the cache size can be controlled using the grails.urlmapping.cache.maxsize config property.</p>
+ *
* @author Marc Palmer (marc@anyware.co.uk)
*/
-public class ControllerArtefactHandler extends ArtefactHandlerAdapter {
+public class ControllerArtefactHandler extends ArtefactHandlerAdapter implements GrailsApplicationAware {
+ private static final String URL_MAPPING_CACHE_MAX_SIZE = "grails.urlmapping.cache.maxsize";
+ private static final GrailsClass NO_CONTROLLER = new AbstractGrailsClass(Object.class, "Controller") {};
+
public static final String TYPE = "Controller";
public static final String PLUGIN_NAME = "controllers";
- private ConcurrentHashMap<String, GrailsClass> uriToControllerClassCache;
+ private ConcurrentLinkedHashMap<String, GrailsClass> uriToControllerClassCache;
private ArtefactInfo artefactInfo;
+ private GrailsApplication grailsApplication;
+
public ControllerArtefactHandler() {
super(TYPE, GrailsControllerClass.class, DefaultGrailsControllerClass.class,
DefaultGrailsControllerClass.CONTROLLER, false);
@@ -36,7 +49,16 @@ public ControllerArtefactHandler() {
@Override
public void initialize(ArtefactInfo artefacts) {
- uriToControllerClassCache = new ConcurrentHashMap<String, GrailsClass>();
+ Object cacheSize = grailsApplication.getFlatConfig().get(URL_MAPPING_CACHE_MAX_SIZE);
+ if (cacheSize == null) {
+ cacheSize = 10000;
+ }
+
+ uriToControllerClassCache = new ConcurrentLinkedHashMap.Builder<String, GrailsClass>()
+ .initialCapacity(500)
+ .maximumWeightedCapacity(new Integer(cacheSize.toString()))
+ .build();
+
artefactInfo = artefacts;
}
@@ -63,13 +85,23 @@ public GrailsClass getArtefactForFeature(Object feature) {
break;
}
}
- if (controllerClass != null) {
- // don't cache for dev environment
- if (Environment.getCurrent() != Environment.DEVELOPMENT) {
- uriToControllerClassCache.putIfAbsent(uri, controllerClass);
- }
+ if (controllerClass == null) {
+ controllerClass = NO_CONTROLLER;
}
+
+ // don't cache for dev environment
+ if (Environment.getCurrent() != Environment.DEVELOPMENT) {
+ uriToControllerClassCache.put(uri, controllerClass);
+ }
+ }
+
+ if (controllerClass == NO_CONTROLLER) {
+ controllerClass = null;
}
return controllerClass;
}
+
+ public void setGrailsApplication(GrailsApplication grailsApplication) {
+ this.grailsApplication = grailsApplication;
+ }
}

0 comments on commit d92969c

Please sign in to comment.
Something went wrong with that request. Please try again.