首页
学习
活动
专区
圈层
工具
发布

@Cacheable中key的SPEL表达式实现

Spring中的@Cacheable注解相信大家都有用过,其key属性是支持SPEL表达式的,像key="#root.args[0]"取到的就是方法第一个入参,这极大地简化了缓存key的配置。...,获取真正存入缓存中的key值        String key = parseSpelKey(cacheable, context);        //读取缓存        Object value...//设置缓存            setCache(cacheable, key, value);        }        return value;    }    private String... parseSpelKey(CacheableTtl cacheable, StandardEvaluationContext context) {        String keySpel = cacheable.key... = expression.getValue(context, String.class);        return key;    }}拦截器设置好后,在Controller层就可以像使用@Cacheable

1K10
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    cacheable更新_详解Spring缓存注解@Cacheable,@CachePut , @CacheEvict使用

    @Cacheable @Cacheable 的作用 主要针对方法配置,能够根据方法的请求参数对其结果进行缓存 @Cacheable 作用和配置方法 参数 解释 example value 缓存的名称,...在 spring 配置文件中定义,必须指定至少一个 例如: @Cacheable(value=”mycache”) @Cacheable(value={”cache1”,”cache2”} key 缓存的...key,可以为空,如果指定要按照 SpEL 表达式编写,如果不指定,则缺省按照方法的所有参数进行组合 @Cacheable(value=”testcache”,key=”#userName”) condition...true,则查缓存; @Cacheable(value = “user”, key = “#id”, condition = “#id lt 10”) public User conditionFindById...= { @Cacheable(value = “user”, key = “#username”) }, put = { @CachePut(value = “user”, key = “#result.id

    4.9K20

    玩转Spring Cache --- @Cacheable使用在MyBatis的Mapper接口上(解决Null key returned for cache operation)【享学Spring】

    比如本文的知识点,从网络的世界里你能找到有人介绍说:@Cacheable不仅仅能标注在实例方法上,也能标注在接口方法上。...顿时丈二的和尚了有木有,难道网上说法有误是个坑:@Cacheable不能使用在接口上吗? 其实都不是,而是因为Spring它只说了其一,并没有说其二。...MapperScan扫进去了 public interface CacheDemoMapper { @Select("select * from user where id = #{id}") @Cacheable...下面我给小伙伴们介绍三种,任君选择 方案一:使用a0/p0的方式去对方法入参进行引用 说了很多次了,key中使用SpEL表达式,即可用字段名,也可以用a0/p0这种按照顺序的方式去获取,形如这样: @Cacheable...{ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Inherited @Documented @Cacheable

    4.9K51

    Spring缓存注解@Cacheable、@CacheEvict、@CachePut

    @Cacheable @Cacheable 的作用 主要针对方法配置,能够根据方法的请求参数对其结果进行缓存 参数 解释 example value 缓存的名称,在 spring 配置文件中定义,必须指定至少一个...例如:@Cacheable(value="mycache") @Cacheable(value={"cache1","cache2"} key 缓存的 key,可以为空,如果指定要按照 SpEL 表达式编写...,如果不指定,则缺省按照方法的所有参数进行组合 @Cacheable(value="testcache",key="#userName") condition 缓存的条件,可以为空,使用 SpEL 编写...缓存的 key,可以为空,如果指定要按照 SpEL 表达式编写,如果不指定,则缺省按照方法的所有参数进行组合 @CachePut(value="testcache",key="#userName")...缓存的 key,可以为空,如果指定要按照 SpEL 表达式编写,如果不指定,则缺省按照方法的所有参数进行组合 @CacheEvict(value="testcache",key="#userName"

    2.2K20

    混合拼接

    例如当前基因组拼接中,尤其对于一些大型的基因组,往往混合多种测序平台数据进行拼接,达到最佳的拼接效果。...这些数据有多种分析方案,例如以下方案: 方案一:二代 illumina 数据单独拼接 方案二:三代数据单独拼接 方案三:二代 illumina 数据为主+三代测序连接...+补洞; 方案四:三代测序单独拼接,利用二代数据连接+纠错; 由于另种数据拼接结果肯定要优于只使用一种数据,因此,这里只需要比较方案三与方案四。...三、不同基因组拼接方案比较 3.1 单独使用 illumina 拼接 spades.py --isolate -o ill -t 24 -1 /share/home/xiehs/05.assembly/...利用 quast 比较不同拼接方案的拼接结果,选择最优的拼接结果。

    2K20
    领券