spring cache注解


1.@CacheConfig(cacheNames = "name")
用在类上的注解,给类中所有方法添加cacheNames属性

2.@Cacheable
@Cacheable( cacheNames = "name" ,key = "123",condition = "#orderForm.openid.length()>3",unless = "")

cacheNames 与key 共同组成redis中的key值, 如果key不写,会默认获取方法中的参数值,也可以舒勇spel表达式直接获取参数值

 @Cacheable( cacheNames = "name" ,key = "#id",condition = "#id.length()>3",unless = "#result.length == 3")
    public String test1(String id){
        //
    return str ; }
condition : 只有传入id的长度大于3,才会缓存
unless(如果不) : 依据结果进行缓存 , 此处为 result的长度 不为3是否成立 ,成立就缓存

缓存的值为方法的返回值

   3.@CacheEvict(cacheNames = "name" ,key = "#id")  清除缓存

 public String test(String id){

    //

    }

   4.@CachePut(cacheNames = "name" ,key = "#id")  更新缓存内容  比如进行save之后,更新缓存


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM