Class NoCache<K,V>

java.lang.Object
org.miaixz.bus.core.cache.provider.NoCache<K,V>
Type Parameters:
K - 键类型
V - 值类型
All Implemented Interfaces:
Serializable, Iterable<V>, Cache<K,V>

public class NoCache<K,V> extends Object implements Cache<K,V>
无缓存实现,用于快速关闭缓存
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    返回包含键和值得迭代器
    int
    返回缓存容量,0表示无大小限制
    void
    清空缓存
    boolean
    是否包含key
    get(K key)
    从缓存中获得对象,当对象不在缓存中或已经过期返回null 调用此方法时,会检查上次调用时间,如果与当前时间差值大于超时时间返回null,否则返回值。 每次调用此方法会刷新最后访问时间,也就是说会重新计算超时时间。
    get(K key, boolean isUpdateLastAccess)
    从缓存中获得对象,当对象不在缓存中或已经过期(与当前时间差值大于超时时间)返回null,否则返回值。 每次调用此方法会可选是否刷新最后访问时间,true表示会重新计算超时时间。
    get(K key, boolean isUpdateLastAccess, long timeout, SupplierX<V> supplier)
    从缓存中获得对象,当对象不在缓存中或已经过期(与当前时间差值大于超时时间)返回 SupplierX 回调产生的对象,否则返回值。 每次调用此方法会可选是否刷新最后访问时间,true表示会重新计算超时时间。
    get(K key, boolean isUpdateLastAccess, SupplierX<V> supplier)
    从缓存中获得对象,当对象不在缓存中或已经过期(与当前时间差值大于超时时间)返回 SupplierX 回调产生的对象,否则返回值。 每次调用此方法会可选是否刷新最后访问时间,true表示会重新计算超时时间。
    get(K key, SupplierX<V> supplier)
    从缓存中获得对象,当对象不在缓存中或已经过期(与当前时间差值大于超时时间)返回 SupplierX 回调产生的对象,否则返回值。 每次调用此方法会刷新最后访问时间,也就是说会重新计算超时时间。
    boolean
    缓存是否为空
    boolean
    缓存是否已满,仅用于有空间限制的缓存对象
     
    int
    从缓存中清理过期对象,清理策略取决于具体实现
    void
    put(K key, V object)
    将对象加入到缓存,使用默认失效时长
    void
    put(K key, V object, long timeout)
    将对象加入到缓存,使用指定失效时长 如果缓存空间满了,Cache.prune() 将被调用以获得空间来存放新对象
    void
    remove(K key)
    从缓存中移除对象
    int
    缓存的对象数量
    long
    缓存失效时长, 0 表示没有设置,单位毫秒

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.miaixz.bus.core.cache.Cache

    setListener

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Constructor Details

    • NoCache

      public NoCache()
  • Method Details

    • capacity

      public int capacity()
      Description copied from interface: Cache
      返回缓存容量,0表示无大小限制
      Specified by:
      capacity in interface Cache<K,V>
      Returns:
      返回缓存容量,0表示无大小限制
    • timeout

      public long timeout()
      Description copied from interface: Cache
      缓存失效时长, 0 表示没有设置,单位毫秒
      Specified by:
      timeout in interface Cache<K,V>
      Returns:
      缓存失效时长, 0 表示没有设置,单位毫秒
    • put

      public void put(K key, V object)
      Description copied from interface: Cache
      将对象加入到缓存,使用默认失效时长
      Specified by:
      put in interface Cache<K,V>
      Parameters:
      key - 键
      object - 缓存的对象
      See Also:
    • put

      public void put(K key, V object, long timeout)
      Description copied from interface: Cache
      将对象加入到缓存,使用指定失效时长 如果缓存空间满了,Cache.prune() 将被调用以获得空间来存放新对象
      Specified by:
      put in interface Cache<K,V>
      Parameters:
      key - 键
      object - 缓存的对象
      timeout - 失效时长,单位毫秒
    • containsKey

      public boolean containsKey(K key)
      Description copied from interface: Cache
      是否包含key
      Specified by:
      containsKey in interface Cache<K,V>
      Parameters:
      key - KEY
      Returns:
      是否包含key
    • get

      public V get(K key)
      Description copied from interface: Cache
      从缓存中获得对象,当对象不在缓存中或已经过期返回null 调用此方法时,会检查上次调用时间,如果与当前时间差值大于超时时间返回null,否则返回值。 每次调用此方法会刷新最后访问时间,也就是说会重新计算超时时间。
      Specified by:
      get in interface Cache<K,V>
      Parameters:
      key - 键
      Returns:
      键对应的对象
      See Also:
    • get

      public V get(K key, boolean isUpdateLastAccess)
      Description copied from interface: Cache
      从缓存中获得对象,当对象不在缓存中或已经过期(与当前时间差值大于超时时间)返回null,否则返回值。 每次调用此方法会可选是否刷新最后访问时间,true表示会重新计算超时时间。
      Specified by:
      get in interface Cache<K,V>
      Parameters:
      key - 键
      isUpdateLastAccess - 是否更新最后访问时间,即重新计算超时时间。
      Returns:
      键对应的对象
    • get

      public V get(K key, SupplierX<V> supplier)
      Description copied from interface: Cache
      从缓存中获得对象,当对象不在缓存中或已经过期(与当前时间差值大于超时时间)返回 SupplierX 回调产生的对象,否则返回值。 每次调用此方法会刷新最后访问时间,也就是说会重新计算超时时间。
      Specified by:
      get in interface Cache<K,V>
      Parameters:
      key - 键
      supplier - 如果不存在回调方法,用于生产值对象
      Returns:
      值对象
    • get

      public V get(K key, boolean isUpdateLastAccess, SupplierX<V> supplier)
      Description copied from interface: Cache
      从缓存中获得对象,当对象不在缓存中或已经过期(与当前时间差值大于超时时间)返回 SupplierX 回调产生的对象,否则返回值。 每次调用此方法会可选是否刷新最后访问时间,true表示会重新计算超时时间。
      Specified by:
      get in interface Cache<K,V>
      Parameters:
      key - 键
      isUpdateLastAccess - 是否更新最后访问时间,即重新计算超时时间。
      supplier - 如果不存在回调方法,用于生产值对象
      Returns:
      值对象
    • get

      public V get(K key, boolean isUpdateLastAccess, long timeout, SupplierX<V> supplier)
      Description copied from interface: Cache
      从缓存中获得对象,当对象不在缓存中或已经过期(与当前时间差值大于超时时间)返回 SupplierX 回调产生的对象,否则返回值。 每次调用此方法会可选是否刷新最后访问时间,true表示会重新计算超时时间。
      Specified by:
      get in interface Cache<K,V>
      Parameters:
      key - 键
      isUpdateLastAccess - 是否更新最后访问时间,即重新计算超时时间。
      timeout - 自定义超时时间
      supplier - 如果不存在回调方法,用于生产值对象
      Returns:
      值对象
    • iterator

      public Iterator<V> iterator()
      Specified by:
      iterator in interface Iterable<K>
    • cacheObjIterator

      public Iterator<CacheObject<K,V>> cacheObjIterator()
      Description copied from interface: Cache
      返回包含键和值得迭代器
      Specified by:
      cacheObjIterator in interface Cache<K,V>
      Returns:
      缓存对象迭代器
    • prune

      public int prune()
      Description copied from interface: Cache
      从缓存中清理过期对象,清理策略取决于具体实现
      Specified by:
      prune in interface Cache<K,V>
      Returns:
      清理的缓存对象个数
    • isFull

      public boolean isFull()
      Description copied from interface: Cache
      缓存是否已满,仅用于有空间限制的缓存对象
      Specified by:
      isFull in interface Cache<K,V>
      Returns:
      缓存是否已满,仅用于有空间限制的缓存对象
    • remove

      public void remove(K key)
      Description copied from interface: Cache
      从缓存中移除对象
      Specified by:
      remove in interface Cache<K,V>
      Parameters:
      key - 键
    • clear

      public void clear()
      Description copied from interface: Cache
      清空缓存
      Specified by:
      clear in interface Cache<K,V>
    • size

      public int size()
      Description copied from interface: Cache
      缓存的对象数量
      Specified by:
      size in interface Cache<K,V>
      Returns:
      缓存的对象数量
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Cache
      缓存是否为空
      Specified by:
      isEmpty in interface Cache<K,V>
      Returns:
      缓存是否为空