Annotation Interface CacheTimeOut


@Target(METHOD) @Retention(RUNTIME) @Documented @Inherited public @interface CacheTimeOut
缓存数据,可以设置超时时间
所有的缓存条件的判断顺序是
1. condition < 2. removeCondition < 3. updateCondition < 4. key < 5. unless
即:
1. 放入缓存的条件判断,就是如果已经符合了,才会进行缓存操作
2. 如果删除了,就不需要更新了
3. 获取了结果,才能对结果进行更新,这里如果需要更行更新才会去获取结果,就可以直接返回了
4. 这里如果缓存里面没有 key 才会去获取结果
5. 这里肯定是缓存里没有 key,然后并且已经获取到了结果,才能对结果进行判断,判断是否要存入缓存,在判断之前如果缓存里面有数据,就直接获取缓存里面的数据
所以,removeCondition 和其他的条件如果使用了,后面的条件就无效了
  • 必需元素概要

    所需元素
    修饰符和类型
    必需的元素
    说明
    Names of the caches in which method invocation results are stored.
    Spring Expression Language (SpEL) expression for computing the key dynamically.
  • 可选元素概要

    可选元素
    修饰符和类型
    可选元素
    说明
    Spring Expression Language (SpEL) expression used for making the method caching conditional.
    (SpEL)
    删除 key 的条件,即当条件为 true 的时候,删除 key,并且不再执行缓存操作
    long
    超时时间 默认 60
    时间单位 默认秒
    Spring Expression Language (SpEL) expression used to veto method caching.
    (SpEL)
    更新 key 的条件,即当条件为 true 的时候更新 key,并且直接返回
    更新的对象的参数名,这里如果不指定,默认拿第一个参数
  • 元素详细资料

    • cacheName

      String cacheName
      Names of the caches in which method invocation results are stored.
      返回:
      缓存名
    • key

      String key
      Spring Expression Language (SpEL) expression for computing the key dynamically.

      (SpEL)
      这个 key 如果是或者是经过 SpEL表达式计算的结果是使用 ","隔开,表示同时操作多个 key

      返回:
      SqEL 表达式获取 key 名
    • timeout

      long timeout
      超时时间 默认 60
      返回:
      超时时间
      默认值:
      60L
    • timeUnit

      TimeUnit timeUnit
      时间单位 默认秒
      返回:
      时间单位
      默认值:
      SECONDS
    • condition

      String condition
      Spring Expression Language (SpEL) expression used for making the method caching conditional. Default is "", meaning the method result is always cached.

      (SpEL)
      缓存条件,与 @Cacheable 里面的 condition 一样,用来判定是否决定要缓存数据 这里要求表达式最终得到的结果要是一个 boolean 即 "true" 或者 "false",不过不管怎么样,只要不是 "true" 或者 "" 就都不会缓存

      返回:
      缓存条件
      默认值:
      ""
    • unless

      String unless
      Spring Expression Language (SpEL) expression used to veto method caching. Unlike condition, this expression is evaluated after the method has been called and can therefore refer to the result. Default is "", meaning that caching is never vetoed.

      (SpEL)
      当 unless 指定的条件为 true ,方法的返回值就不会被缓存,这里可以使用 #result 来引用返回结果

      返回:
      对返回结果做处理的条件
      默认值:
      ""
    • removeCondition

      String removeCondition
      (SpEL)
      删除 key 的条件,即当条件为 true 的时候,删除 key,并且不再执行缓存操作
      返回:
      删除 key 的条件
      默认值:
      ""
    • updateCondition

      String updateCondition
      (SpEL)
      更新 key 的条件,即当条件为 true 的时候更新 key,并且直接返回
      返回:
      更新 key 的条件
      默认值:
      ""
    • updateObject

      String updateObject
      更新的对象的参数名,这里如果不指定,默认拿第一个参数
      返回:
      参数名
      默认值:
      ""