From 857eadff4554eb9d630d55f5171d7e00706276ec Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Wed, 1 Nov 2017 11:09:14 -0400 Subject: [PATCH] Avoid complications with merges in the session cache, evict and then update. --- .../java/net/helenus/core/HelenusSession.java | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/main/java/net/helenus/core/HelenusSession.java b/src/main/java/net/helenus/core/HelenusSession.java index 4c9b15f..f61b1cc 100644 --- a/src/main/java/net/helenus/core/HelenusSession.java +++ b/src/main/java/net/helenus/core/HelenusSession.java @@ -234,7 +234,7 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab } String tableName = CacheUtil.schemaName(facets); List facetCombinations = CacheUtil.flattenFacets(boundFacets); - mergeAndUpdateCacheValues(pojo, tableName, facetCombinations); + replaceCachedFacetValues(pojo, tableName, facetCombinations); } @Override @@ -265,10 +265,9 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab boundFacets.add(facet); } } - // NOTE: should equal `String tableName = CacheUtil.schemaName(facets);` List facetCombinations = CacheUtil.flattenFacets(boundFacets); String tableName = CacheUtil.schemaName(boundFacets); - mergeAndUpdateCacheValues(pojo, tableName, facetCombinations); + replaceCachedFacetValues(pojo, tableName, facetCombinations); } } @@ -284,21 +283,11 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab } } - private void mergeAndUpdateCacheValues(Object pojo, String tableName, List facetCombinations) { - Object merged = null; + private void replaceCachedFacetValues(Object pojo, String tableName, List facetCombinations) { for (String[] combination : facetCombinations) { String cacheKey = tableName + "." + Arrays.toString(combination); - Object value = sessionCache.get(cacheKey); - if (value == null) { - sessionCache.put(cacheKey, pojo); - } else { - if (merged == null) { - merged = pojo; - } else { - merged = CacheUtil.merge(value, pojo); - } - sessionCache.put(cacheKey, merged); - } + sessionCache.invalidate(cacheKey); + sessionCache.put(cacheKey, pojo); } }