From 85207086e663323757bb1a16926833a63d57885c Mon Sep 17 00:00:00 2001 From: rob bygrave Date: Tue, 21 Apr 2020 21:55:51 +1200 Subject: [PATCH] #1995 - ENH: Add DatabaseConfig.isLocalOnlyL2Cache() ... to support disabling l2 cache plugins --- .../java/io/ebean/config/ServerConfig.java | 20 +++++++++++++++++++ .../server/core/InternalConfiguration.java | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/ebean/config/ServerConfig.java b/src/main/java/io/ebean/config/ServerConfig.java index 34d5f2f83..b4a83e5f0 100644 --- a/src/main/java/io/ebean/config/ServerConfig.java +++ b/src/main/java/io/ebean/config/ServerConfig.java @@ -475,6 +475,11 @@ public class ServerConfig { private String enabledL2Regions; + /** + * Set to true to effectively disable L2 cache plugins. + */ + private boolean localOnlyL2Cache; + /** * Should the javax.validation.constraints.NotNull enforce a notNull column in DB. * If set to false, use io.ebean.annotation.NotNull or Column(nullable=true). @@ -2860,6 +2865,7 @@ public class ServerConfig { collectQueryPlanThresholdMicros = p.getLong("collectQueryPlanThresholdMicros", collectQueryPlanThresholdMicros); docStoreOnly = p.getBoolean("docStoreOnly", docStoreOnly); disableL2Cache = p.getBoolean("disableL2Cache", disableL2Cache); + localOnlyL2Cache = p.getBoolean("localOnlyL2Cache", localOnlyL2Cache); enabledL2Regions = p.get("enabledL2Regions", enabledL2Regions); notifyL2CacheInForeground = p.getBoolean("notifyL2CacheInForeground", notifyL2CacheInForeground); explicitTransactionBeginMode = p.getBoolean("explicitTransactionBeginMode", explicitTransactionBeginMode); @@ -3100,6 +3106,20 @@ public class ServerConfig { this.disableL2Cache = disableL2Cache; } + /** + * Return true to use local only L2 cache. Effectively ignore l2 cache plugin like ebean-redis etc. + */ + public boolean isLocalOnlyL2Cache() { + return localOnlyL2Cache; + } + + /** + * Force the use of local only L2 cache. Effectively ignore l2 cache plugin like ebean-redis etc. + */ + public void setLocalOnlyL2Cache(boolean localOnlyL2Cache) { + this.localOnlyL2Cache = localOnlyL2Cache; + } + /** * Returns if we use javax.validation.constraints.NotNull */ diff --git a/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java b/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java index 38501baa5..c069bdd87 100644 --- a/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java +++ b/src/main/java/io/ebeaninternal/server/core/InternalConfiguration.java @@ -617,7 +617,7 @@ public class InternalConfiguration { */ private SpiCacheManager initCacheManager() { - if (!online || serverConfig.isDisableL2Cache()) { + if (!online || serverConfig.isDisableL2Cache() || serverConfig.isLocalOnlyL2Cache()) { // use local only L2 cache implementation as placeholder return new DefaultServerCacheManager(); }