diff --git a/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/TimestampsRegionImpl.java b/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/TimestampsRegionImpl.java index eae8519e5f..946ac7993f 100644 --- a/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/timestamp/TimestampsRegionImpl.java +++ b/cache-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/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapter.java b/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapter.java index aa61371ded..af1db37f72 100644 --- a/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapter.java +++ b/cache-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/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapterImpl.java b/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapterImpl.java index 26be9683d8..2b89508850 100644 --- a/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheAdapterImpl.java +++ b/cache-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/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheHelper.java b/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheHelper.java index 923c2b06a2..a563970b97 100644 --- a/cache-infinispan/src/main/java/org/hibernate/cache/infinispan/util/CacheHelper.java +++ b/cache-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) {