spring的redis注解缓冲数据批量操作@Cacheable、@Cacheput、@CacheEvict

概述

  在进行redis的操作的时候,有时候需要对多个键一起操作。那么注解如何可以进行批量的操作呢,这个地方就使用到了这个@Cacheing。

    @Caching(
            evict = {
                    @CacheEvict(value = "default",
                            key = "T(org.loulan.dawn.application.common.pojo.config.redis.RedisArea).USER_DAWN_RESOURCE + #userId",
                            unless = "#result == true "),
                    @CacheEvict(value = "default",
                            key = "T(org.loulan.dawn.application.common.pojo.config.redis.RedisArea).USER_VUE_ELEMENT_RESOURCE + #userId",
                            unless = "#result == true "),
                    @CacheEvict(value = "default",
                            key = "T(org.loulan.dawn.application.common.pojo.config.redis.RedisArea).USER_VUE_MENU_RESOURCE + #userId",
                            unless = "#result == true ")
            }
    )
    public Boolean insertUserRole(List roleIds, String userId){}

  也可以在里面添加put和cacheable

    @Caching(
            put = {
                    @CachePut(value = "default",
                            key = "T(org.loulan.dawn.application.common.pojo.config.redis.RedisArea).USER_INFO + #userId",
                            unless = "#result == null")
            },
            evict = {
                    @CacheEvict(value = "default",
                            key = "T(org.loulan.dawn.application.common.pojo.config.redis.RedisArea).USER_DAWN_RESOURCE + #userId",
                            unless = "#result == null ")
            }
    )
    public User insertUserRole(List roleIds, String userId){}

注解得使用

你可能感兴趣的:(#,spirng)