mirror of
https://github.com/chillzhuang/blade-tool
synced 2024-12-12 12:19:27 +08:00
⚡ 优化CacheUtil
This commit is contained in:
parent
4c9546af8c
commit
791a5f2596
@ -105,8 +105,26 @@ public class CacheUtil {
|
||||
if (Func.hasEmpty(cacheName, keyPrefix, key)) {
|
||||
return null;
|
||||
}
|
||||
String cacheKey = keyPrefix.concat(String.valueOf(key));
|
||||
return getCache(cacheName).get(cacheKey, valueLoader);
|
||||
|
||||
final String fullKey = keyPrefix.concat(String.valueOf(key));
|
||||
Cache cache = getCache(cacheName);
|
||||
Cache.ValueWrapper valueWrapper = cache.get(fullKey);
|
||||
|
||||
if (valueWrapper != null) {
|
||||
return (T) valueWrapper.get();
|
||||
}
|
||||
|
||||
try {
|
||||
T value = valueLoader.call();
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
cache.put(fullKey, value);
|
||||
return value;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user