Module bus.cache

Class MemoryCache<K,V>

java.lang.Object
org.miaixz.bus.cache.metric.MemoryCache<K,V>
All Implemented Interfaces:
CacheX<K,V>

public class MemoryCache<K,V> extends Object implements CacheX<K,V>
内存缓存支持
Since:
Java 17+
Author:
Kimi Liu
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static boolean
    是否开启定时clear() ()}的任务
    static long
    默认缓存过期时间:3分钟 鉴于授权过程中,根据个人的操作习惯,或者授权平台的不同(google等),每个授权流程的耗时也有差异,不过单个授权流程一般不会太长 本缓存工具默认的过期时间设置为3分钟,即程序默认认为3分钟内的授权有效,超过3分钟则默认失效,失效后删除
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    清理过期的缓存
    boolean
    是否存在key,如果对应key的value值已过期,也返回false
    read(Collection<K> keys)
    从缓存中获得一组对象信息
    read(K key)
    获取缓存
    void
    remove(K... keys)
    清理过期的缓存
    void
    schedulePrune(long delay)
    定时清理
    void
    write(Map<K,V> keyValueMap, long expire)
    设置缓存
    void
    write(K key, V value, long expire)
    设置缓存

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • timeout

      public static long timeout
      默认缓存过期时间:3分钟 鉴于授权过程中,根据个人的操作习惯,或者授权平台的不同(google等),每个授权流程的耗时也有差异,不过单个授权流程一般不会太长 本缓存工具默认的过期时间设置为3分钟,即程序默认认为3分钟内的授权有效,超过3分钟则默认失效,失效后删除
    • schedulePrune

      public static boolean schedulePrune
      是否开启定时clear() ()}的任务
  • Constructor Details

    • MemoryCache

      public MemoryCache()
  • Method Details

    • read

      public V read(K key)
      获取缓存
      Specified by:
      read in interface CacheX<K,V>
      Parameters:
      key - 缓存KEY
      Returns:
      缓存内容
    • read

      public Map<K,V> read(Collection<K> keys)
      Description copied from interface: CacheX
      从缓存中获得一组对象信息
      Specified by:
      read in interface CacheX<K,V>
      Parameters:
      keys - 多个键
      Returns:
      值对象
    • write

      public void write(Map<K,V> keyValueMap, long expire)
      设置缓存
      Specified by:
      write in interface CacheX<K,V>
      Parameters:
      keyValueMap - 缓存内容
      expire - 指定缓存过期时间(毫秒)
      See Also:
    • write

      public void write(K key, V value, long expire)
      设置缓存
      Specified by:
      write in interface CacheX<K,V>
      Parameters:
      key - 缓存KEY
      value - 缓存内容
      expire - 指定缓存过期时间(毫秒)
    • containsKey

      public boolean containsKey(K key)
      Description copied from interface: CacheX
      是否存在key,如果对应key的value值已过期,也返回false
      Specified by:
      containsKey in interface CacheX<K,V>
      Parameters:
      key - 缓存key
      Returns:
      true:存在key,并且value没过期;false:key不存在或者已过期
    • clear

      public void clear()
      清理过期的缓存
      Specified by:
      clear in interface CacheX<K,V>
    • remove

      public void remove(K... keys)
      清理过期的缓存
      Specified by:
      remove in interface CacheX<K,V>
      Parameters:
      keys - 键
    • schedulePrune

      public void schedulePrune(long delay)
      定时清理
      Parameters:
      delay - 间隔时长,单位毫秒