Class AbstractStampManager<K,V>

java.lang.Object
cn.herodotus.engine.cache.jetcache.stamp.AbstractStampManager<K,V>
Type Parameters:
K - 签章缓存对应Key值的类型。
V - 签章缓存存储数据,对应的具体存储值的类型,
All Implemented Interfaces:
StampManager<K,V>, org.springframework.beans.factory.InitializingBean
Direct Known Subclasses:
AbstractCountStampManager

public abstract class AbstractStampManager<K,V> extends Object implements StampManager<K,V>

Description: 抽象Stamp管理

Author:
: gengwei.zheng
Date:
: 2021/8/23 11:51
  • Constructor Details

    • AbstractStampManager

      public AbstractStampManager(String cacheName)
    • AbstractStampManager

      public AbstractStampManager(String cacheName, com.alicp.jetcache.anno.CacheType cacheType)
    • AbstractStampManager

      public AbstractStampManager(String cacheName, com.alicp.jetcache.anno.CacheType cacheType, Duration expire)
  • Method Details

    • getCache

      protected com.alicp.jetcache.Cache<K,V> getCache()
      指定数据存储缓存
      Returns:
      Cache
    • getExpire

      public Duration getExpire()
      Description copied from interface: StampManager
      过期时间
      Specified by:
      getExpire in interface StampManager<K,V>
      Returns:
      Duration
    • setExpire

      public void setExpire(Duration expire)
    • check

      public boolean check(K key, V value) throws cn.herodotus.engine.cache.core.exception.StampParameterIllegalException, cn.herodotus.engine.cache.core.exception.StampHasExpiredException, cn.herodotus.engine.cache.core.exception.StampMismatchException
      Description copied from interface: StampManager
      校验Stamp值,与本地存储的Stamp 是否匹配
      Specified by:
      check in interface StampManager<K,V>
      Parameters:
      key - 与Stamp对应的Key值
      value - 外部传入的Stamp值
      Returns:
      ture 匹配,false 不匹配
      Throws:
      cn.herodotus.engine.cache.core.exception.StampParameterIllegalException - 传入Stamp错误
      cn.herodotus.engine.cache.core.exception.StampHasExpiredException - 本地数据中没有Stamp或者Stamp已经过期。
      cn.herodotus.engine.cache.core.exception.StampMismatchException - Stamp与本地存储值不匹配
    • get

      public V get(K key)
      Description copied from interface: StampManager
      根据key读取Stamp
      Specified by:
      get in interface StampManager<K,V>
      Parameters:
      key - 存储数据Key值
      Returns:
      存储的Stamp值
    • delete

      public void delete(K key)
      Description copied from interface: StampManager
      删除与Key对应的Stamp
      Specified by:
      delete in interface StampManager<K,V>
      Parameters:
      key - 存储数据Key值
    • put

      public void put(K key, V value, long expireAfterWrite, TimeUnit timeUnit)
      Description copied from interface: StampManager
      保存与Key对应的Stamp签章值
      Specified by:
      put in interface StampManager<K,V>
      Parameters:
      key - 存储Key
      value - 与Key对应的Stamp
      expireAfterWrite - 过期时间
      timeUnit - 过期时间单位
    • lock

      public com.alicp.jetcache.AutoReleaseLock lock(K key, long expire, TimeUnit timeUnit)
      Description copied from interface: StampManager
      锁定值

      非堵塞的尝试获取一个锁,如果对应的key还没有锁,返回一个AutoReleaseLock,否则立即返回空。如果Cache实例是本地的,它是一个本地锁,在本JVM中有效;如果是redis等远程缓存,它是一个不十分严格的分布式锁。锁的超时时间由expire和timeUnit指定。多级缓存的情况会使用最后一级做tryLock操作。

      Specified by:
      lock in interface StampManager<K,V>
      Parameters:
      key - 存储Key
      expire - 过期时间
      timeUnit - 过期时间单位
      Returns:
      AutoReleaseLock
      See Also:
    • lockAndRun

      public boolean lockAndRun(K key, long expire, TimeUnit timeUnit, Runnable action)
      Description copied from interface: StampManager
      锁定并执行操作

      非堵塞的尝试获取一个锁,如果对应的key还没有锁,返回一个AutoReleaseLock,否则立即返回空。如果Cache实例是本地的,它是一个本地锁,在本JVM中有效;如果是redis等远程缓存,它是一个不十分严格的分布式锁。锁的超时时间由expire和timeUnit指定。多级缓存的情况会使用最后一级做tryLock操作。

      Specified by:
      lockAndRun in interface StampManager<K,V>
      Parameters:
      key - 存储Key
      expire - 过期时间
      timeUnit - 过期时间单位
      action - 需要执行的操作 Runnable
      Returns:
      是否执行成功
      See Also: