HHH-5793 - All put/remove calls should skip cache load and remote get
This commit is contained in:
parent
287f67d0b4
commit
66f555e52a
|
@ -84,8 +84,7 @@ public class TimestampsRegionImpl extends BaseGeneralDataRegion implements Times
|
||||||
try {
|
try {
|
||||||
// We ensure ASYNC semantics (JBCACHE-1175) and make sure previous
|
// We ensure ASYNC semantics (JBCACHE-1175) and make sure previous
|
||||||
// value is not loaded from cache store cos it's not needed.
|
// value is not loaded from cache store cos it's not needed.
|
||||||
cacheAdapter.withFlags(FlagAdapter.FORCE_ASYNCHRONOUS,
|
cacheAdapter.withFlags(FlagAdapter.FORCE_ASYNCHRONOUS).put(key, value);
|
||||||
FlagAdapter.SKIP_CACHE_LOAD).put(key, value);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CacheException(e);
|
throw new CacheException(e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -101,27 +101,25 @@ public interface CacheAdapter {
|
||||||
Object getAllowingTimeout(Object key) throws CacheException;
|
Object getAllowingTimeout(Object key) throws CacheException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a <code>put(Object, Object)</code> on the cache, wrapping any exception in a {@link CacheException}.
|
* Performs a <code>put(Object, Object)</code> on the cache,
|
||||||
|
* wrapping any exception in a {@link CacheException}.
|
||||||
*
|
*
|
||||||
* @param key key whose value will be modified
|
* @param key key whose value will be modified
|
||||||
* @param value data to store in the cache entry
|
* @param value data to store in the cache entry
|
||||||
* @return the previous value associated with <tt>key</tt>, or <tt>null</tt>
|
|
||||||
* if there was no mapping for <tt>key</tt>.
|
|
||||||
* @throws CacheException
|
* @throws CacheException
|
||||||
*/
|
*/
|
||||||
Object put(Object key, Object value) throws CacheException;
|
void put(Object key, Object value) throws CacheException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a <code>put(Object, Object)</code> on the cache ignoring any {@link TimeoutException}
|
* Performs a <code>put(Object, Object)</code> on the cache ignoring
|
||||||
* and wrapping any exception in a {@link CacheException}.
|
* any {@link TimeoutException} and wrapping any exception in a
|
||||||
|
* {@link CacheException}.
|
||||||
*
|
*
|
||||||
* @param key key whose value will be modified
|
* @param key key whose value will be modified
|
||||||
* @param value data to store in the cache entry
|
* @param value data to store in the cache entry
|
||||||
* @return the previous value associated with <tt>key</tt>, or <tt>null</tt>
|
|
||||||
* if there was no mapping for <tt>key</tt>.
|
|
||||||
* @throws CacheException
|
* @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.
|
* See {@link Cache#putForExternalRead(Object, Object)} for detailed documentation.
|
||||||
|
@ -133,14 +131,13 @@ public interface CacheAdapter {
|
||||||
void putForExternalRead(Object key, Object value) throws CacheException;
|
void putForExternalRead(Object key, Object value) throws CacheException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a <code>remove(Object)</code>, wrapping any exception in a {@link CacheException}.
|
* Performs a <code>remove(Object)</code>, wrapping any exception in
|
||||||
|
* a {@link CacheException}.
|
||||||
*
|
*
|
||||||
* @param key key to be removed
|
* @param key key to be removed
|
||||||
* @return the previous value associated with <tt>key</tt>, or
|
|
||||||
* <tt>null</tt> if there was no mapping for <tt>key</tt>.
|
|
||||||
* @throws CacheException
|
* @throws CacheException
|
||||||
*/
|
*/
|
||||||
Object remove(Object key) throws CacheException;
|
void remove(Object key) throws CacheException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Evict the given key from memory.
|
* Evict the given key from memory.
|
||||||
|
|
|
@ -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 {
|
try {
|
||||||
return cache.put(key, value);
|
// No previous value interest, so apply flags that avoid remote lookups.
|
||||||
|
getSkipRemoteGetLoadCache().put(key, value);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CacheException(e);
|
throw new CacheException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object putAllowingTimeout(Object key, Object value) throws CacheException {
|
public void putAllowingTimeout(Object key, Object value) throws CacheException {
|
||||||
try {
|
try {
|
||||||
return getFailSilentCache().put(key, value);
|
// No previous value interest, so apply flags that avoid remote lookups.
|
||||||
|
getFailSilentCacheSkipRemotes().put(key, value);
|
||||||
} catch (TimeoutException allowed) {
|
} catch (TimeoutException allowed) {
|
||||||
// ignore it
|
// ignore it
|
||||||
return null;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CacheException(e);
|
throw new CacheException(e);
|
||||||
}
|
}
|
||||||
|
@ -115,15 +116,17 @@ public class CacheAdapterImpl implements CacheAdapter {
|
||||||
|
|
||||||
public void putForExternalRead(Object key, Object value) throws CacheException {
|
public void putForExternalRead(Object key, Object value) throws CacheException {
|
||||||
try {
|
try {
|
||||||
cache.putForExternalRead(key, value);
|
// No previous value interest, so apply flags that avoid remote lookups.
|
||||||
|
getFailSilentCacheSkipRemotes().putForExternalRead(key, value);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CacheException(e);
|
throw new CacheException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object remove(Object key) throws CacheException {
|
public void remove(Object key) throws CacheException {
|
||||||
try {
|
try {
|
||||||
return cache.remove(key);
|
// No previous value interest, so apply flags that avoid remote lookups.
|
||||||
|
getSkipRemoteGetLoadCache().remove(key);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new CacheException(e);
|
throw new CacheException(e);
|
||||||
}
|
}
|
||||||
|
@ -214,4 +217,15 @@ public class CacheAdapterImpl implements CacheAdapter {
|
||||||
private Cache getFailSilentCache() {
|
private Cache getFailSilentCache() {
|
||||||
return cache.getAdvancedCache().withFlags(Flag.FAIL_SILENTLY);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,14 +48,14 @@ public class CacheHelper {
|
||||||
private 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);
|
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);
|
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) {
|
public static boolean isEvictAllNotification(Object key) {
|
||||||
|
|
Loading…
Reference in New Issue