修改了空值的情况
parent
b29e58bc62
commit
0cb04c8799
|
@ -47,8 +47,17 @@ public abstract class HashCacheAbs<K, HK, HV> implements HashCache<K, HK, HV> {
|
||||||
@Override
|
@Override
|
||||||
public Map<HK, HV> get (K key) {
|
public Map<HK, HV> get (K key) {
|
||||||
// 获取为null的情况
|
// 获取为null的情况
|
||||||
|
Map<String, HV> cacheMap = redisService.getCacheMap(encode(key));
|
||||||
return decodeMap(redisService.getCacheMap(encode(key)));
|
if (cacheMap == null || cacheMap.isEmpty()){
|
||||||
|
Map<HK, HV> dataMap = getData(key);
|
||||||
|
if (dataMap != null && !dataMap.isEmpty()){
|
||||||
|
cacheMap = encodeMap(dataMap);
|
||||||
|
}else {
|
||||||
|
cacheMap = encodeMap(defaultValue());
|
||||||
|
}
|
||||||
|
redisService.setCacheMap(encode(key), cacheMap);
|
||||||
|
}
|
||||||
|
return decodeMap(cacheMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,7 +70,13 @@ public abstract class HashCacheAbs<K, HK, HV> implements HashCache<K, HK, HV> {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public HV get (K key, HK hashKey) {
|
public HV get (K key, HK hashKey) {
|
||||||
return redisService.getCacheMapValue(encode(key), encodeHashKey(hashKey));
|
HV hashValue = redisService.getCacheMapValue(encode(key), encodeHashKey(hashKey));
|
||||||
|
if (hashValue == null){
|
||||||
|
HV dataValue = getData(key, hashKey);
|
||||||
|
hashValue = dataValue != null ? dataValue : defaultHashValue();
|
||||||
|
put(key, hashKey, hashValue);
|
||||||
|
}
|
||||||
|
return hashValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue