File tree Expand file tree Collapse file tree
simple-framework/src/main/java/top/cadecode/framework/model/service Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111 */
1212public interface SecurityApiService {
1313
14+ /**
15+ * api role 缓存前缀
16+ */
17+ String API_ROLE_CACHE_PREFIX = "security:api.role:list" ;
18+
19+
1420 /**
1521 * 查询所有接口及其角色
1622 *
Original file line number Diff line number Diff line change 22
33import lombok .RequiredArgsConstructor ;
44import org .springframework .cache .annotation .Cacheable ;
5+ import org .springframework .data .redis .core .RedisTemplate ;
56import org .springframework .stereotype .Service ;
67import top .cadecode .framework .model .mapper .SecurityApiMapper ;
78import top .cadecode .framework .model .service .SecurityApiService ;
89import top .cadecode .framework .model .vo .SecurityApiVo ;
910
1011import java .util .List ;
12+ import java .util .Optional ;
1113
1214/**
1315 * @author Cade Li
1921public class SecurityApiServiceImpl implements SecurityApiService {
2022
2123 private final SecurityApiMapper securityApiMapper ;
24+ private final RedisTemplate <String , List <SecurityApiVo >> redisTemplate ;
2225
23- @ Cacheable (cacheNames = "apiRoleCache" , cacheManager = "securityCacheManager " )
26+ @ Cacheable (cacheNames = API_ROLE_CACHE_PREFIX , cacheManager = "caffeineCache " )
2427 @ Override
2528 public List <SecurityApiVo > listSecurityApiVos () {
26- return securityApiMapper .listSecurityApiVos ();
29+ List <SecurityApiVo > securityApiVos = redisTemplate .opsForValue ().get (API_ROLE_CACHE_PREFIX );
30+ return Optional .ofNullable (securityApiVos )
31+ .orElseGet (() -> {
32+ List <SecurityApiVo > vos = securityApiMapper .listSecurityApiVos ();
33+ redisTemplate .opsForValue ().set (API_ROLE_CACHE_PREFIX , vos );
34+ return vos ;
35+ });
2736 }
2837}
You can’t perform that action at this time.
0 commit comments