From 04da27507ed317395239494be92ec65b9477b842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Galder=20Zamarre=C3=B1o?= Date: Wed, 12 Jan 2011 15:09:08 +0100 Subject: [PATCH] HHH-5793 - All put/remove calls should skip cache load and remote get --- .../timestamp/TimestampsRegionImpl.java | 3 +- .../cache/infinispan/util/CacheAdapter.java | 23 +++++++------- .../infinispan/util/CacheAdapterImpl.java | 30 ++++++++++++++----- .../cache/infinispan/util/CacheHelper.java | 8 ++--- 4 files changed, 37 insertions(+), 27 deletions(-) diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/TimestampsRegionImpl.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/TimestampsRegionImpl.java index eae8519e5f..946ac7993f 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/TimestampsRegionImpl.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/TimestampsRegionImpl.java @@ -84,8 +84,7 @@ public class TimestampsRegionImpl extends BaseGeneralDataRegion implements Times try { // We ensure ASYNC semantics (JBCACHE-1175) and make sure previous // value is not loaded from cache store cos it's not needed. - cacheAdapter.withFlags(FlagAdapter.FORCE_ASYNCHRONOUS, - FlagAdapter.SKIP_CACHE_LOAD).put(key, value); + cacheAdapter.withFlags(FlagAdapter.FORCE_ASYNCHRONOUS).put(key, value); } catch (Exception e) { throw new CacheException(e); } finally { diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapter.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapter.java index aa61371ded..af1db37f72 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapter.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapter.java @@ -101,27 +101,25 @@ public interface CacheAdapter { Object getAllowingTimeout(Object key) throws CacheException; /** - * Performs a put(Object, Object) on the cache, wrapping any exception in a {@link CacheException}. + * Performs a put(Object, Object) on the cache, + * wrapping any exception in a {@link CacheException}. * * @param key key whose value will be modified * @param value data to store in the cache entry - * @return the previous value associated with key, or null - * if there was no mapping for key. * @throws CacheException */ - Object put(Object key, Object value) throws CacheException; + void put(Object key, Object value) throws CacheException; /** - * Performs a put(Object, Object) on the cache ignoring any {@link TimeoutException} - * and wrapping any exception in a {@link CacheException}. + * Performs a put(Object, Object) on the cache ignoring + * any {@link TimeoutException} and wrapping any exception in a + * {@link CacheException}. * * @param key key whose value will be modified * @param value data to store in the cache entry - * @return the previous value associated with key, or null - * if there was no mapping for key. * @throws CacheException */ - Object putAllowingTimeout(Object key, Object value) throws CacheException; + void putAllowingTimeout(Object key, Object value) throws CacheException; /** * See {@link Cache#putForExternalRead(Object, Object)} for detailed documentation. @@ -133,14 +131,13 @@ public interface CacheAdapter { void putForExternalRead(Object key, Object value) throws CacheException; /** - * Performs a remove(Object), wrapping any exception in a {@link CacheException}. + * Performs a remove(Object), wrapping any exception in + * a {@link CacheException}. * * @param key key to be removed - * @return the previous value associated with key, or - * null if there was no mapping for key. * @throws CacheException */ - Object remove(Object key) throws CacheException; + void remove(Object key) throws CacheException; /** * Evict the given key from memory. diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapterImpl.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapterImpl.java index 26be9683d8..2b89508850 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapterImpl.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapterImpl.java @@ -94,20 +94,21 @@ public class CacheAdapterImpl implements CacheAdapter { } } - public Object put(Object key, Object value) throws CacheException { + public void put(Object key, Object value) throws CacheException { try { - return cache.put(key, value); + // No previous value interest, so apply flags that avoid remote lookups. + getSkipRemoteGetLoadCache().put(key, value); } catch (Exception e) { throw new CacheException(e); } } - public Object putAllowingTimeout(Object key, Object value) throws CacheException { + public void putAllowingTimeout(Object key, Object value) throws CacheException { try { - return getFailSilentCache().put(key, value); + // No previous value interest, so apply flags that avoid remote lookups. + getFailSilentCacheSkipRemotes().put(key, value); } catch (TimeoutException allowed) { // ignore it - return null; } catch (Exception e) { throw new CacheException(e); } @@ -115,15 +116,17 @@ public class CacheAdapterImpl implements CacheAdapter { public void putForExternalRead(Object key, Object value) throws CacheException { try { - cache.putForExternalRead(key, value); + // No previous value interest, so apply flags that avoid remote lookups. + getFailSilentCacheSkipRemotes().putForExternalRead(key, value); } catch (Exception e) { throw new CacheException(e); } } - public Object remove(Object key) throws CacheException { + public void remove(Object key) throws CacheException { try { - return cache.remove(key); + // No previous value interest, so apply flags that avoid remote lookups. + getSkipRemoteGetLoadCache().remove(key); } catch (Exception e) { throw new CacheException(e); } @@ -214,4 +217,15 @@ public class CacheAdapterImpl implements CacheAdapter { private Cache getFailSilentCache() { return cache.getAdvancedCache().withFlags(Flag.FAIL_SILENTLY); } + + private Cache getSkipRemoteGetLoadCache() { + return cache.getAdvancedCache().withFlags( + Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP); + } + + private Cache getFailSilentCacheSkipRemotes() { + return cache.getAdvancedCache().withFlags( + Flag.FAIL_SILENTLY, Flag.SKIP_CACHE_LOAD, Flag.SKIP_REMOTE_LOOKUP); + } + } diff --git a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheHelper.java b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheHelper.java index 923c2b06a2..a563970b97 100644 --- a/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheHelper.java +++ b/hibernate-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheHelper.java @@ -48,14 +48,14 @@ public class CacheHelper { private CacheHelper() { } - public static void initInternalEvict(CacheAdapter cacheAdapter, AddressAdapter member) { + public static void initInternalEvict(CacheAdapter cache, AddressAdapter member) { EvictAll eKey = new EvictAll(member == null ? NoAddress.INSTANCE : member); - cacheAdapter.withFlags(FlagAdapter.CACHE_MODE_LOCAL, FlagAdapter.SKIP_CACHE_LOAD).put(eKey, Internal.INIT); + cache.withFlags(FlagAdapter.CACHE_MODE_LOCAL).put(eKey, Internal.INIT); } - public static void sendEvictAllNotification(CacheAdapter cacheAdapter, AddressAdapter member) { + public static void sendEvictAllNotification(CacheAdapter cache, AddressAdapter member) { EvictAll eKey = new EvictAll(member == null ? NoAddress.INSTANCE : member); - cacheAdapter.withFlags(FlagAdapter.SKIP_CACHE_LOAD).put(eKey, Internal.EVICT); + cache.put(eKey, Internal.EVICT); } public static boolean isEvictAllNotification(Object key) {