Ensure that the session cache is only used on entity objects marked @Cacheable.
This commit is contained in:
parent
852ee59da2
commit
d25061366b
12 changed files with 47 additions and 18 deletions
|
@ -213,8 +213,10 @@ public abstract class AbstractUnitOfWork<E extends Exception> implements UnitOfW
|
|||
});
|
||||
// log.record(txn::abort)
|
||||
// cache.invalidateSince(txn::start time)
|
||||
elapsedTime_.stop();
|
||||
logTimers("aborted");
|
||||
if (!hasAborted()) {
|
||||
elapsedTime_.stop();
|
||||
logTimers("aborted");
|
||||
}
|
||||
}
|
||||
|
||||
private void mergeCache(Table<String, String, Object> from) {
|
||||
|
|
|
@ -72,9 +72,9 @@ public abstract class AbstractOptionalOperation<E, O extends AbstractOptionalOpe
|
|||
try {
|
||||
Optional<E> result = Optional.empty();
|
||||
E cacheResult = null;
|
||||
boolean updateCache = true;
|
||||
boolean updateCache = isSessionCacheable();
|
||||
|
||||
if (enableCache) {
|
||||
if (enableCache && isSessionCacheable()) {
|
||||
List<Facet> facets = bindFacetValues();
|
||||
String tableName = CacheUtil.schemaName(facets);
|
||||
cacheResult = (E)sessionOps.checkCache(tableName, facets);
|
||||
|
@ -95,7 +95,10 @@ public abstract class AbstractOptionalOperation<E, O extends AbstractOptionalOpe
|
|||
}
|
||||
|
||||
if (updateCache && result.isPresent()) {
|
||||
sessionOps.updateCache(result.get(), getFacets());
|
||||
List<Facet> facets = getFacets();
|
||||
if (facets != null && facets.size() > 1) {
|
||||
sessionOps.updateCache(result.get(), facets);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} finally {
|
||||
|
@ -123,10 +126,12 @@ public abstract class AbstractOptionalOperation<E, O extends AbstractOptionalOpe
|
|||
result = Optional.of(cacheResult);
|
||||
updateCache = false;
|
||||
} else {
|
||||
String tableName = CacheUtil.schemaName(facets);
|
||||
cacheResult = (E)sessionOps.checkCache(tableName, facets);
|
||||
if (cacheResult != null) {
|
||||
result = Optional.of(cacheResult);
|
||||
if (isSessionCacheable()) {
|
||||
String tableName = CacheUtil.schemaName(facets);
|
||||
cacheResult = (E) sessionOps.checkCache(tableName, facets);
|
||||
if (cacheResult != null) {
|
||||
result = Optional.of(cacheResult);
|
||||
}
|
||||
}
|
||||
}
|
||||
timer.stop();
|
||||
|
|
|
@ -66,9 +66,9 @@ public abstract class AbstractStreamOperation<E, O extends AbstractStreamOperati
|
|||
try {
|
||||
Stream<E> resultStream = null;
|
||||
E cacheResult = null;
|
||||
boolean updateCache = true;
|
||||
boolean updateCache = isSessionCacheable();
|
||||
|
||||
if (enableCache) {
|
||||
if (enableCache && isSessionCacheable()) {
|
||||
List<Facet> facets = bindFacetValues();
|
||||
String tableName = CacheUtil.schemaName(facets);
|
||||
cacheResult = (E) sessionOps.checkCache(tableName, facets);
|
||||
|
@ -89,13 +89,15 @@ public abstract class AbstractStreamOperation<E, O extends AbstractStreamOperati
|
|||
}
|
||||
|
||||
if (updateCache && resultStream != null) {
|
||||
List<E> again = new ArrayList<>();
|
||||
List<Facet> facets = getFacets();
|
||||
resultStream.forEach(result -> {
|
||||
sessionOps.updateCache(result, facets);
|
||||
again.add(result);
|
||||
});
|
||||
resultStream = again.stream();
|
||||
if (facets != null && facets.size() > 1) {
|
||||
List<E> again = new ArrayList<>();
|
||||
resultStream.forEach(result -> {
|
||||
sessionOps.updateCache(result, facets);
|
||||
again.add(result);
|
||||
});
|
||||
resultStream = again.stream();
|
||||
}
|
||||
}
|
||||
return resultStream;
|
||||
|
||||
|
|
|
@ -39,4 +39,7 @@ public final class BoundOperation<E> extends AbstractOperation<E, BoundOperation
|
|||
public Statement buildStatement(boolean cached) {
|
||||
return boundStatement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSessionCacheable() { return delegate.isSessionCacheable(); }
|
||||
}
|
||||
|
|
|
@ -41,4 +41,7 @@ public final class BoundOptionalOperation<E> extends AbstractOptionalOperation<E
|
|||
public Statement buildStatement(boolean cached) {
|
||||
return boundStatement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSessionCacheable() { return delegate.isSessionCacheable(); }
|
||||
}
|
||||
|
|
|
@ -49,4 +49,7 @@ public final class BoundStreamOperation<E> extends AbstractStreamOperation<E, Bo
|
|||
public Statement buildStatement(boolean cached) {
|
||||
return boundStatement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSessionCacheable() { return delegate.isSessionCacheable(); }
|
||||
}
|
||||
|
|
|
@ -104,4 +104,6 @@ public abstract class Operation<E> {
|
|||
return null;
|
||||
}
|
||||
|
||||
public boolean isSessionCacheable() { return false; }
|
||||
|
||||
}
|
||||
|
|
|
@ -43,4 +43,5 @@ public final class PreparedOperation<E> {
|
|||
public String toString() {
|
||||
return preparedStatement.getQueryString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -59,4 +59,7 @@ public final class SelectFirstOperation<E> extends AbstractFilterOptionalOperati
|
|||
public Optional<E> transform(ResultSet resultSet) {
|
||||
return delegate.transform(resultSet).findFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSessionCacheable() { return delegate.isSessionCacheable(); }
|
||||
}
|
||||
|
|
|
@ -54,4 +54,7 @@ public final class SelectFirstTransformingOperation<R, E>
|
|||
public Optional<R> transform(ResultSet resultSet) {
|
||||
return delegate.transform(resultSet).findFirst().map(fn);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSessionCacheable() { return delegate.isSessionCacheable(); }
|
||||
}
|
||||
|
|
|
@ -185,6 +185,9 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
|
|||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSessionCacheable() { return isCacheable; }
|
||||
|
||||
@Override
|
||||
public List<Facet> getFacets() {
|
||||
HelenusEntity entity = props.get(0).getEntity();
|
||||
|
|
|
@ -21,7 +21,6 @@ import net.helenus.mapping.annotation.PartitionKey;
|
|||
import net.helenus.mapping.annotation.Table;
|
||||
|
||||
@Table("simple_users")
|
||||
@Cacheable
|
||||
public interface User {
|
||||
|
||||
@PartitionKey
|
||||
|
|
Loading…
Reference in a new issue