修改了空值的情况

master
DongZeLiang 2024-04-01 11:30:38 +08:00
parent b29e58bc62
commit 0cb04c8799
1 changed files with 18 additions and 3 deletions

View File

@ -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;
} }
/** /**