Spring boot redis 实现缓存
2017-10-15 16:34
48 查看
配置 redis
@Configuration @EnableCaching public class RedisConfig extends CachingConfigurerSupport { @Value("${spring.redis.host}") private String host; @Value("${spring.redis.port}") private int port; @Value("${spring.redis.timeout}") private int timeout; //缓存管理器 @Bean public CacheManager cacheManager(@SuppressWarnings("rawtypes") RedisTemplate redisTemplate) { RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate); //设置缓存过期时间 cacheManager.setDefaultExpiration(30000); return cacheManager; } @Bean public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory){ StringRedisTemplate template = new StringRedisTemplate(factory); setSerializer(template);//设置序列化工具 template.afterPropertiesSet(); return template; } private void setSerializer(StringRedisTemplate template){ @SuppressWarnings({ "rawtypes", "unchecked" }) Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class); ObjectMapper om = new ObjectMapper(); om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY); om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL); jackson2JsonRedisSerializer.setObjectMapper(om); template.setValueSerializer(jackson2JsonRedisSerializer); }
在DAO上加上缓存标准
@CacheConfig@Cacheable
可以参考文章
/detail/2703699569.html
http://jinnianshilongnian.iteye.com/blog/2001040
/detail/2703229040.html
/detail/2697693424.html
相关文章推荐
- spring+quartz实现定时任务(每天零点删除指定文件夹中缓存文件)
- spring结合redis如何实现数据的缓存
- spring boot+spring cache实现两级缓存(redis+caffeine)
- spring + redis实现缓存
- 在 Spring 3.1 中使用 @Cacheable 实现缓存
- 整合SpringBoot+Mysql+Redis实现缓存机制的一个Demo
- SpringBoot中使用Redis实现缓存
- spring + redis 实现数据的缓存
- SpringBoot集成Redis来实现缓存技术方案
- 利用Spring AOP 更新memcached 缓存策略的实现(二)
- 170316、spring4:@Cacheable和@CacheEvict实现缓存及集成redis
- Spring Boot 整合 Redis 实现缓存操作
- springboot redis 缓存对象
- SpringBoot整合Spring-data-redis实现集中式缓存
- 利用Spring AOP 更新memcached 缓存策略的实现
- spring和ehcache整合,实现基于注解的缓存实现
- Spring Boot项目利用Redis实现集中式缓存
- spring aop aspect + annotation实现缓存命中判断
- spring+springmvc+mybatis+redis实现缓存
- redis整合spring实现对数据的缓存