SGF-327 - Avoid setting null values with GemFire's Cache Region put(key, value) operation when GemFire is used as the caching provider in Spring's Cache Abstraction (@Cacheable).
This commit is contained in:
@@ -71,11 +71,11 @@ public class GemfireCache implements Cache {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T get(final Object key, final Class<T> type) {
|
||||
|
||||
Object value = region.get(key);
|
||||
|
||||
if (value != null && type != null && !type.isInstance(value)) {
|
||||
throw new IllegalStateException("Cached value is not of required type [" + type.getName() + "]: " + value);
|
||||
throw new IllegalStateException(String.format("Cached value is not of required type [%1$s]: %2$s",
|
||||
type.getName(), value));
|
||||
}
|
||||
|
||||
return (T) value;
|
||||
@@ -83,7 +83,9 @@ public class GemfireCache implements Cache {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void put(final Object key, final Object value) {
|
||||
region.put(key, value);
|
||||
if (value != null) {
|
||||
region.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,8 +96,9 @@ public class GemfireCache implements Cache {
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ValueWrapper putIfAbsent(Object key, Object value) {
|
||||
|
||||
Object existingValue = region.putIfAbsent(key, value);
|
||||
return existingValue == null ? null : new SimpleValueWrapper(existingValue);
|
||||
|
||||
return (existingValue == null ? null : new SimpleValueWrapper(existingValue));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -84,8 +84,7 @@ public class GemfireCacheManager extends AbstractCacheManager {
|
||||
Cache cache = super.getCache(name);
|
||||
|
||||
if (cache == null) {
|
||||
// check the gemfire cache again
|
||||
// in case the cache was added at runtime
|
||||
// check the GemFire Cache again in case the Cache (Region) was added at runtime
|
||||
Region<?, ?> region = gemfireCache.getRegion(name);
|
||||
|
||||
if (region != null) {
|
||||
|
||||
Reference in New Issue
Block a user