HHH-5793 - All put/remove calls should skip cache load and remote get

This commit is contained in:
Galder Zamarreño 2011-01-12 15:09:08 +01:00
parent 287f67d0b4
commit 66f555e52a
4 changed files with 37 additions and 27 deletions

View File

@ -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 {

View File

@ -101,27 +101,25 @@ public interface CacheAdapter {
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 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
*/
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}
* and wrapping any exception in a {@link CacheException}.
* Performs a <code>put(Object, Object)</code> 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 <tt>key</tt>, or <tt>null</tt>
* if there was no mapping for <tt>key</tt>.
* @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 <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
* @return the previous value associated with <tt>key</tt>, or
* <tt>null</tt> if there was no mapping for <tt>key</tt>.
* @throws CacheException
*/
Object remove(Object key) throws CacheException;
void remove(Object key) throws CacheException;
/**
* Evict the given key from memory.

View File

@ -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);
}
}

View File

@ -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) {