@Cacheable设置过期时间
参考:https://blog.csdn.net/liuyueyi25/article/details/118422143
使用@Cacheable时,无法直接设置过期时间,需要自定义RedisCacheManager来实现ttl设置。
注意:项目中已配置了RedisCacheManager需要在原配置的bean上添加注解**@Primary**,以免造成干扰
/**
自定义RedisCacheManager,用于在使用@Cacheable时设置ttl
*/
@Bean
public RedisCacheManager selfCacheManager(RedisTemplate<String, Object> redisTemplate) {
RedisCacheWriter redisCacheWriter = RedisCacheWriter.nonLockingRedisCacheWriter(redisTemplate.getConnectionFactory());
RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration