From 707dda636d3baa8f34e724716263c613c83d0d22 Mon Sep 17 00:00:00 2001 From: Robin Bygrave Date: Wed, 13 Apr 2016 17:44:37 +1200 Subject: [PATCH] #649 - ENH: Add ebean.disableL2Cache=true option ... to globally disable l2 cache --- .../com/avaje/ebean/config/ServerConfig.java | 20 +++++++++++++++++++ .../cache/DefaultServerCacheManager.java | 7 +++++++ .../server/core/DefaultContainer.java | 4 ++++ .../server/deploy/BeanDescriptorManager.java | 2 +- .../server/deploy/parse/AnnotationClass.java | 9 ++++++++- .../server/deploy/parse/ReadAnnotations.java | 7 +++++-- 6 files changed, 45 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/avaje/ebean/config/ServerConfig.java b/src/main/java/com/avaje/ebean/config/ServerConfig.java index fc6f3fc65..a376aee37 100644 --- a/src/main/java/com/avaje/ebean/config/ServerConfig.java +++ b/src/main/java/com/avaje/ebean/config/ServerConfig.java @@ -405,6 +405,11 @@ public class ServerConfig { private String jodaLocalTimeMode; + /** + * Set to true to globally disable L2 caching (typically for performance testing). + */ + private boolean disableL2Cache; + /** * Construct a Server Configuration for programmatically creating an EbeanServer. */ @@ -2313,6 +2318,7 @@ public class ServerConfig { } loadDocStoreSettings(p); + disableL2Cache = p.getBoolean("disableL2Cache", disableL2Cache); explicitTransactionBeginMode = p.getBoolean("explicitTransactionBeginMode", explicitTransactionBeginMode); autoCommitMode = p.getBoolean("autoCommitMode", autoCommitMode); useJtaTransactionManager = p.getBoolean("useJtaTransactionManager", useJtaTransactionManager); @@ -2501,6 +2507,20 @@ public class ServerConfig { this.expressionEqualsWithNullAsNoop = expressionEqualsWithNullAsNoop; } + /** + * Return true if L2 cache is disabled. + */ + public boolean isDisableL2Cache() { + return disableL2Cache; + } + + /** + * Set to true to disable L2 caching. Typically useful in performance testing. + */ + public void setDisableL2Cache(boolean disableL2Cache) { + this.disableL2Cache = disableL2Cache; + } + /** * Specify how UUID is stored. */ diff --git a/src/main/java/com/avaje/ebeaninternal/server/cache/DefaultServerCacheManager.java b/src/main/java/com/avaje/ebeaninternal/server/cache/DefaultServerCacheManager.java index defde3a77..052f1ccd6 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/cache/DefaultServerCacheManager.java +++ b/src/main/java/com/avaje/ebeaninternal/server/cache/DefaultServerCacheManager.java @@ -37,6 +37,13 @@ public class DefaultServerCacheManager implements ServerCacheManager { this.collectionIdsCache = new DefaultCacheHolder(cacheFactory, defaultQueryOptions, false); } + /** + * Construct when l2 cache is disabled. + */ + public DefaultServerCacheManager() { + this(new DefaultServerCacheFactory(), new ServerCacheOptions(), new ServerCacheOptions()); + } + public void init(EbeanServer server) { cacheFactory.init(server); this.ebeanServer = (SpiEbeanServer) server; diff --git a/src/main/java/com/avaje/ebeaninternal/server/core/DefaultContainer.java b/src/main/java/com/avaje/ebeaninternal/server/core/DefaultContainer.java index ffc80b7f9..8258287ad 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/core/DefaultContainer.java +++ b/src/main/java/com/avaje/ebeaninternal/server/core/DefaultContainer.java @@ -149,6 +149,10 @@ public class DefaultContainer implements SpiContainer { */ private ServerCacheManager getCacheManager(ServerConfig serverConfig) { + if (serverConfig.isDisableL2Cache()) { + return new DefaultServerCacheManager(); + } + ServerCacheManager serverCacheManager = serverConfig.getServerCacheManager(); if (serverCacheManager != null) { return serverCacheManager; diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptorManager.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptorManager.java index deb74d963..9e3f41fab 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptorManager.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/BeanDescriptorManager.java @@ -201,7 +201,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap { this.asOfViewSuffix = getAsOfViewSuffix(databasePlatform, serverConfig); String versionsBetweenSuffix = getVersionsBetweenSuffix(databasePlatform, serverConfig); - this.readAnnotations = new ReadAnnotations(config.getGeneratedPropertyFactory(), asOfViewSuffix, versionsBetweenSuffix); + this.readAnnotations = new ReadAnnotations(config.getGeneratedPropertyFactory(), asOfViewSuffix, versionsBetweenSuffix, serverConfig.isDisableL2Cache()); this.bootupClasses = config.getBootupClasses(); this.createProperties = config.getDeployCreateProperties(); this.namingConvention = serverConfig.getNamingConvention(); diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/AnnotationClass.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/AnnotationClass.java index eda36ef56..f7050ba0e 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/AnnotationClass.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/AnnotationClass.java @@ -43,13 +43,16 @@ public class AnnotationClass extends AnnotationParser { private final String versionsBetweenSuffix; + private final boolean disableL2Cache; + /** * Create for normal early parse of class level annotations. */ - public AnnotationClass(DeployBeanInfo info, boolean validationAnnotations, String asOfViewSuffix, String versionsBetweenSuffix) { + public AnnotationClass(DeployBeanInfo info, boolean validationAnnotations, String asOfViewSuffix, String versionsBetweenSuffix, boolean disableL2Cache) { super(info, validationAnnotations); this.asOfViewSuffix = asOfViewSuffix; this.versionsBetweenSuffix = versionsBetweenSuffix; + this.disableL2Cache = disableL2Cache; } /** @@ -60,6 +63,7 @@ public class AnnotationClass extends AnnotationParser { super(info, false); this.asOfViewSuffix = null; this.versionsBetweenSuffix = null; + this.disableL2Cache = false; } /** @@ -210,6 +214,9 @@ public class AnnotationClass extends AnnotationParser { private void readCacheStrategy(CacheStrategy cacheStrategy, CacheTuning cacheTuning) { + if (disableL2Cache) { + return; + } CacheOptions cacheOptions = descriptor.getCacheOptions(); if (cacheTuning != null) { cacheOptions.setMaxSecsToLive(cacheTuning.maxSecsToLive()); diff --git a/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/ReadAnnotations.java b/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/ReadAnnotations.java index 49b829abf..22d031495 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/ReadAnnotations.java +++ b/src/main/java/com/avaje/ebeaninternal/server/deploy/parse/ReadAnnotations.java @@ -32,12 +32,15 @@ public class ReadAnnotations { */ private final boolean jacksonAnnotations; - public ReadAnnotations(GeneratedPropertyFactory generatedPropFactory, String asOfViewSuffix, String versionsBetweenSuffix) { + private final boolean disableL2Cache; + + public ReadAnnotations(GeneratedPropertyFactory generatedPropFactory, String asOfViewSuffix, String versionsBetweenSuffix, boolean disableL2Cache) { this.generatedPropFactory = generatedPropFactory; this.asOfViewSuffix = asOfViewSuffix; this.versionsBetweenSuffix = versionsBetweenSuffix; this.javaxValidationAnnotations = generatedPropFactory.getClassLoadConfig().isJavaxValidationAnnotationsPresent(); this.jacksonAnnotations = generatedPropFactory.getClassLoadConfig().isJacksonAnnotationsPresent(); + this.disableL2Cache = disableL2Cache; } /** @@ -50,7 +53,7 @@ public class ReadAnnotations { public void readInitial(DeployBeanInfo info, boolean eagerFetchLobs) { try { - new AnnotationClass(info, javaxValidationAnnotations, asOfViewSuffix, versionsBetweenSuffix).parse(); + new AnnotationClass(info, javaxValidationAnnotations, asOfViewSuffix, versionsBetweenSuffix, disableL2Cache).parse(); new AnnotationFields(generatedPropFactory, info, javaxValidationAnnotations, jacksonAnnotations, eagerFetchLobs).parse(); } catch (RuntimeException e) {