#2048 - IllegalStateException: No query cache enabled on __. Need explicit @Cache(enableQueryCache=true) ... when ebean.disableL2Cache=true l2

This commit is contained in:
rob bygrave
2020-08-26 11:33:23 +12:00
parent a626690918
commit b2ce9db8a8
4 changed files with 21 additions and 2 deletions
@@ -33,6 +33,11 @@ import java.util.function.Predicate;
*/
public interface SpiEbeanServer extends ExtendedServer, EbeanServer, BeanCollectionLoader {
/**
* Return true if the L2 cache has been disabled.
*/
boolean isDisableL2Cache();
/**
* Return the log manager.
*/
@@ -249,6 +249,8 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
private final SlowQueryListener slowQueryListener;
private final boolean disableL2Cache;
/**
* Create the DefaultServer.
*/
@@ -256,6 +258,7 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
this.logManager = config.getLogManager();
this.dtoBeanManager = config.getDtoBeanManager();
this.serverConfig = config.getServerConfig();
this.disableL2Cache = serverConfig.isDisableL2Cache();
this.serverCacheManager = cache;
this.databasePlatform = config.getDatabasePlatform();
this.backgroundExecutor = config.getBackgroundExecutor();
@@ -330,6 +333,11 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
}
}
@Override
public boolean isDisableL2Cache() {
return disableL2Cache;
}
@Override
public SpiLogManager log() {
return logManager;
@@ -698,8 +698,9 @@ public final class OrmQueryRequest<T> extends BeanRequest implements SpiOrmQuery
@Override
@SuppressWarnings("unchecked")
public Object getFromQueryCache() {
if (query.getUseQueryCache() == CacheMode.OFF || (transaction != null && transaction.isSkipCache())) {
if (query.getUseQueryCache() == CacheMode.OFF
|| (transaction != null && transaction.isSkipCache())
|| ebeanServer.isDisableL2Cache()) {
return null;
} else {
cacheKey = query.queryHash();
@@ -96,6 +96,11 @@ public class TDSpiEbeanServer implements SpiEbeanServer {
public void setClock(Clock clock) {
}
@Override
public boolean isDisableL2Cache() {
return false;
}
@Override
public SpiLogManager log() {
return null;