REDIS12_Spring Cache概述、@Cacheable、@CacheEvict、@Caching、@CachePut的使用(三)

简介: REDIS12_Spring Cache概述、@Cacheable、@CacheEvict、@Caching、@CachePut的使用(三)
  • ③. 测试得到的结果:


  1. 如果缓存中有,方法不再调用


  1. key是默认自动生成的,包含缓存名字::SimpleKey(自动生成的key值)


  1. 缓存的value的值。默认使用jdk序列化机制,将序列化后的数据存到redis


  1. 默认过期时间是 -1


微信图片_20220109191814.png


image.png


④. 指定自己的key,并设置过期时间


//application.properties
spring.cache.type=redis
#spring.cache.cache-names=
#设置存活时间,ms为单位
spring.cache.redis.time-to-live=3600000


/**
自定义
(1). 指定生成缓存的key key属性指定,接收一个spl表达式
详细文档:https://docs.spring.io/spring-framework/docs/5.2.16.RELEASE/spring-framework-reference/integration.html#cache-spel-context
(2). 指定缓存的数据存活时间(在配置文件中修改了ttl)
*/
@Cacheable(value={"category"},key = "'Level1Categorys'")
@Override
public List<CategoryEntity> getLevel1Category() {
    long l= System.currentTimeMillis();
    QueryWrapper<CategoryEntity> wrapper = new QueryWrapper<>();
    wrapper.eq("parent_cid",0);
    List<CategoryEntity> entities = baseMapper.selectList(wrapper);
    log.info("消耗时间:"+(System.currentTimeMillis()-l));
    return entities;
}


image.png


⑤. 如果使用#root.method.name


  @Cacheable(value={"category"},key = "#root.method.name")


微信图片_20220109191920.png

相关文章
|
存储 缓存 NoSQL
【Azure Redis 缓存】关于Azure Cache for Redis 服务在传输和存储键值对(Key/Value)的加密问题
【Azure Redis 缓存】关于Azure Cache for Redis 服务在传输和存储键值对(Key/Value)的加密问题
356 2
|
NoSQL Unix 网络安全
【Azure Cache for Redis】Python Django-Redis连接Azure Redis服务遇上(104, 'Connection reset by peer')
【Azure Cache for Redis】Python Django-Redis连接Azure Redis服务遇上(104, 'Connection reset by peer')
215 0
【Azure Cache for Redis】Python Django-Redis连接Azure Redis服务遇上(104, 'Connection reset by peer')
|
11月前
|
存储 缓存 NoSQL
Spring Cache缓存框架
Spring Cache是Spring体系下的标准化缓存框架,支持多种缓存(如Redis、EhCache、Caffeine),可独立或组合使用。其优势包括平滑迁移、注解与编程两种使用方式,以及高度解耦和灵活管理。通过动态代理实现缓存操作,适用于不同业务场景。
744 0
|
缓存 弹性计算 NoSQL
【Azure Redis 缓存 Azure Cache For Redis】Redis连接池
【Azure Redis 缓存 Azure Cache For Redis】Redis连接池
234 0
|
存储 缓存 Java
Spring缓存注解【@Cacheable、@CachePut、@CacheEvict、@Caching、@CacheConfig】使用及注意事项
Spring缓存注解【@Cacheable、@CachePut、@CacheEvict、@Caching、@CacheConfig】使用及注意事项
5304 2
|
NoSQL 网络协议 Redis
【Azure Redis】AKS中使用Lettuce连接Redis Cache出现 timed out 问题的解决思路
【Azure Redis】AKS中使用Lettuce连接Redis Cache出现 timed out 问题的解决思路
570 1
【Azure Redis】AKS中使用Lettuce连接Redis Cache出现 timed out 问题的解决思路
|
Java 数据库连接 数据库
让星星⭐月亮告诉你,SSH框架01、Spring概述
Spring是一个轻量级的Java开发框架,旨在简化企业级应用开发。它通过IoC(控制反转)和DI(依赖注入)降低组件间的耦合度,支持AOP(面向切面编程),简化事务管理和数据库操作,并能与多种第三方框架无缝集成,提供灵活的Web层支持,是开发高性能应用的理想选择。
231 1
|
NoSQL Redis 容器
【Azure Cache for Redis】Redis的导出页面无法配置Storage SAS时通过az cli来完成
【Azure Cache for Redis】Redis的导出页面无法配置Storage SAS时通过az cli来完成
187 3
|
缓存 NoSQL Redis
【Azure Redis 缓存】Azure Cache for Redis 服务的导出RDB文件无法在自建的Redis服务中导入
【Azure Redis 缓存】Azure Cache for Redis 服务的导出RDB文件无法在自建的Redis服务中导入
249 0
|
缓存 开发框架 NoSQL
【Azure Redis 缓存】VM 里的 Redis 能直接迁移到 Azure Cache for Redis ? 需要改动代码吗?
【Azure Redis 缓存】VM 里的 Redis 能直接迁移到 Azure Cache for Redis ? 需要改动代码吗?
227 0

热门文章

最新文章