Only use session cache for entites and only when requested.

This commit is contained in:
Greg Burd 2017-10-23 13:37:27 -04:00
parent 682a1a304e
commit 852ee59da2
2 changed files with 13 additions and 2 deletions

View file

@ -15,6 +15,7 @@
*/ */
package net.helenus.core.operation; package net.helenus.core.operation;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
@ -87,13 +88,15 @@ public abstract class AbstractStreamOperation<E, O extends AbstractStreamOperati
resultStream = transform(resultSet); resultStream = transform(resultSet);
} }
if (enableCache && resultStream != null) { if (updateCache && resultStream != null) {
List<E> again = new ArrayList<>();
List<Facet> facets = getFacets(); List<Facet> facets = getFacets();
resultStream.forEach(result -> { resultStream.forEach(result -> {
sessionOps.updateCache(result, facets); sessionOps.updateCache(result, facets);
again.add(result);
}); });
resultStream = again.stream();
} }
return resultStream; return resultStream;
} finally { } finally {
@ -132,10 +135,13 @@ public abstract class AbstractStreamOperation<E, O extends AbstractStreamOperati
// If we have a result and we're caching then we need to put it into the cache // If we have a result and we're caching then we need to put it into the cache
// for future requests to find. // for future requests to find.
if (updateCache && resultStream != null) { if (updateCache && resultStream != null) {
List<E> again = new ArrayList<>();
List<Facet> facets = getFacets(); List<Facet> facets = getFacets();
resultStream.forEach(result -> { resultStream.forEach(result -> {
updateCache(uow, result, facets); updateCache(uow, result, facets);
again.add(result);
}); });
resultStream = again.stream();
} }
return resultStream; return resultStream;

View file

@ -54,6 +54,7 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
protected Integer limit = null; protected Integer limit = null;
protected boolean allowFiltering = false; protected boolean allowFiltering = false;
protected String alternateTableName = null; protected String alternateTableName = null;
protected boolean isCacheable = false;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public SelectOperation(AbstractSessionOperations sessionOperations) { public SelectOperation(AbstractSessionOperations sessionOperations) {
@ -84,6 +85,8 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
entity.getOrderedProperties().stream().map(p -> new HelenusPropertyNode(p, Optional.empty())) entity.getOrderedProperties().stream().map(p -> new HelenusPropertyNode(p, Optional.empty()))
.forEach(p -> this.props.add(p)); .forEach(p -> this.props.add(p));
isCacheable = entity.isCacheable();
} }
public SelectOperation(AbstractSessionOperations sessionOperations, HelenusEntity entity, public SelectOperation(AbstractSessionOperations sessionOperations, HelenusEntity entity,
@ -94,6 +97,8 @@ public final class SelectOperation<E> extends AbstractFilterStreamOperation<E, S
entity.getOrderedProperties().stream().map(p -> new HelenusPropertyNode(p, Optional.empty())) entity.getOrderedProperties().stream().map(p -> new HelenusPropertyNode(p, Optional.empty()))
.forEach(p -> this.props.add(p)); .forEach(p -> this.props.add(p));
isCacheable = entity.isCacheable();
} }
public SelectOperation(AbstractSessionOperations sessionOperations, Function<Row, E> rowMapper, public SelectOperation(AbstractSessionOperations sessionOperations, Function<Row, E> rowMapper,