Honor the ignoreCache() when selecting from UOW cache.
This commit is contained in:
parent
83ef8d7b0c
commit
75aff52312
5 changed files with 19 additions and 15 deletions
2
pom.xml
2
pom.xml
|
@ -5,7 +5,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>net.helenus</groupId>
|
||||
<artifactId>helenus-core</artifactId>
|
||||
<version>2.0.28-SNAPSHOT</version>
|
||||
<version>2.0.29-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>helenus</name>
|
||||
|
|
|
@ -74,18 +74,19 @@ public abstract class AbstractOptionalOperation<E, O extends AbstractOptionalOpe
|
|||
|
||||
Optional<E> result = null;
|
||||
String key = getStatementCacheKey();
|
||||
if (key != null) {
|
||||
if (enableCache && key != null) {
|
||||
Set<E> cachedResult = (Set<E>) uow.cacheLookup(key);
|
||||
if (cachedResult != null) {
|
||||
//TODO(gburd): what about select ResultSet, Tuple... etc.?
|
||||
uowCacheHits.mark();
|
||||
logger.info("UOW({}) cache hit, {} -> {}", uow.hashCode(), key, cachedResult.toString());
|
||||
result = cachedResult.stream().findFirst();
|
||||
} else {
|
||||
uowCacheMiss.mark();
|
||||
}
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
uowCacheMiss.mark();
|
||||
ResultSet resultSet = execute(sessionOps, uow, traceContext, showValues, true);
|
||||
result = transform(resultSet);
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ public abstract class AbstractStatementOperation<E, O extends AbstractStatementO
|
|||
|
||||
public abstract Statement buildStatement(boolean cached);
|
||||
|
||||
protected boolean enableCache = true;
|
||||
protected boolean showValues = true;
|
||||
protected TraceContext traceContext;
|
||||
private ConsistencyLevel consistencyLevel;
|
||||
|
@ -52,6 +53,17 @@ public abstract class AbstractStatementOperation<E, O extends AbstractStatementO
|
|||
this.consistencyLevel = sessionOperations.getDefaultConsistencyLevel();
|
||||
}
|
||||
|
||||
|
||||
public O ignoreCache(boolean enabled) {
|
||||
enableCache = enabled;
|
||||
return (O) this;
|
||||
}
|
||||
|
||||
public O ignoreCache() {
|
||||
enableCache = true;
|
||||
return (O) this;
|
||||
}
|
||||
|
||||
public O showValues(boolean enabled) {
|
||||
this.showValues = enabled;
|
||||
return (O) this;
|
||||
|
|
|
@ -78,18 +78,19 @@ public abstract class AbstractStreamOperation<E, O extends AbstractStreamOperati
|
|||
try {
|
||||
Stream<E> result = null;
|
||||
String key = getStatementCacheKey();
|
||||
if (key != null) {
|
||||
if (enableCache && key != null) {
|
||||
Set<E> cachedResult = (Set<E>) uow.cacheLookup(key);
|
||||
if (cachedResult != null) {
|
||||
//TODO(gburd): what about select ResultSet, Tuple... etc.?
|
||||
uowCacheHits.mark();
|
||||
logger.info("UOW({}) cache hit, {} -> {}", uow.hashCode(), key, cachedResult.toString());
|
||||
result = cachedResult.stream();
|
||||
} else {
|
||||
uowCacheMiss.mark();
|
||||
}
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
uowCacheMiss.mark();
|
||||
ResultSet resultSet = execute(sessionOps, uow, traceContext, showValues, true);
|
||||
result = transform(resultSet);
|
||||
|
||||
|
|
|
@ -48,7 +48,6 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
|||
protected List<Ordering> ordering = null;
|
||||
protected Integer limit = null;
|
||||
protected boolean allowFiltering = false;
|
||||
protected boolean cacheEntity = false;
|
||||
|
||||
public SelectOperation(AbstractSessionOperations sessionOperations) {
|
||||
super(sessionOperations);
|
||||
|
@ -77,8 +76,6 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
|||
|
||||
super(sessionOperations);
|
||||
|
||||
cacheEntity = entity.isCacheable();
|
||||
|
||||
entity
|
||||
.getOrderedProperties()
|
||||
.stream()
|
||||
|
@ -94,8 +91,6 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
|||
super(sessionOperations);
|
||||
this.rowMapper = rowMapper;
|
||||
|
||||
cacheEntity = entity.isCacheable();
|
||||
|
||||
entity
|
||||
.getOrderedProperties()
|
||||
.stream()
|
||||
|
@ -174,11 +169,6 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
|||
return this;
|
||||
}
|
||||
|
||||
public SelectOperation<E> ignoreCache() {
|
||||
cacheEntity = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public SelectOperation<E> limit(Integer limit) {
|
||||
this.limit = limit;
|
||||
return this;
|
||||
|
|
Loading…
Reference in a new issue