zoukankan      html  css  js  c++  java
  • springboot缓存注解——@Cacheable和@CacheConfig

    @Caching :制定多个缓存规则

    @Cacheable 和 @CachePut 同时标注时 ,@CachePut导致还是会走方法跟数据库交互

    //根据lastName查,并将结果缓存,并且可以用于下次通过id或者email查询
    (因为有Cacheput注解,所有根据lastName查的方法还是会执行)
    
    @Caching(
                cacheable = {@Cacheable(/*value = "emp",*/key = "#lastName")},
                put = {@CachePut(/*value = "emp",*/key = "#result.id"),@CachePut(/*value = "emp",*/key = "#result.email")}
        )
        public Employee getEmpByLastName(String lastName){
            System.out.println("根据...."+lastName+"查询员工");
            return  employeeMapper.getEmpByLastName(lastName);
        }


    另外:
    @CacheConfig    :抽取缓存公共配置,可以标注在类上

    如:

    @CacheConfig(cacheNames = "emp")
    @Service
    public class EmployeeService 
  • 相关阅读:
    poj 2391 Ombrophobic Bovines
    混合欧拉回路poj 1637 Sightseeing tour
    POJ1149-PIGS
    C
    B
    A
    C
    B
    A
    O
  • 原文地址:https://www.cnblogs.com/MagicAsa/p/10763275.html
Copyright © 2011-2022 走看看