String pageKey = RedisKeyManagement.getKey(RedisKeyManagement.ACTIVITY_BAISHI_PAGE_CACHE,
Arrays.asList(activityId.toString(),String.valueOf(current)));
Object pageObj = redisService.get(pageKey);
if(pageObj != null) {
return ApiResult.success(pageObj);
}
// 字符串对象要.intern()很重要
synchronized (("lock" + activityId + current).intern()) {
pageObj = redisService.get(pageKey);
if(pageObj != null) {
return ApiResult.success(pageObj);
}
ApiResult<PortalPageVO<PlayRecordBaseExtendVO>> apiResult = 读数据库的请求;
redisService.set(pageKey,apiResult.getData(), Constant.TEN_SECOND);
return apiResult;
}
参考:
https://blog.csdn.net/A_art_xiang/article/details/126340579
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/288180.html