/ **
*
* <P> the Description: </ P>
* @param cache Key Key
* @param The expire cache expiration
* @param clazz
* @param loadBack cache method is performed after the empty
* @return
* /
Private Logger Logger LoggerFactory.getLogger = (CaCheServiceTempl.class);
public <T> T GetCache (String Key, a Date The expire, typereference <T> clazz, CaCheServiceI <T> loadBack) {
String = RedisUtil.get JSON (Key); // where use redis cache
IF (! StringUtils.isNotEmpty (JSON) && json.equalsIgnoreCase ( "null")) {
logger.info ( "cache === redish values acquired in:" + JSON);
// convert problematic because redis data conversion failed not solve
return JSON.parseObject(json, clazz );
}
else {
synchronized(this) {
json = RedisUtil.get(key);
if(StringUtils.isNotEmpty(json)&&json.equalsIgnoreCase("null")) {
return JSON.parseObject(json, clazz);
}
T result = loadBack.loadBack();
if(result != null) {
RedisUtil.set(key, result.toString());
}
return result;
}
}
}
Cache penetrate solve the problem
Guess you like
Origin blog.csdn.net/qq_39057033/article/details/92973638
Recommended
Ranking