Class Cache<K,V>

java.lang.Object
cool.scx.common.cache.Cache<K,V>
Type Parameters:
K -
V -
All Implemented Interfaces:
ICache<K,V>

public class Cache<K,V> extends Object implements ICache<K,V>
默认缓存实现 (永久储存, 达到最大容量后移除之前的元素)
Version:
0.0.1
Author:
scx567888
  • Constructor Details

    • Cache

      public Cache(int maxSize)
    • Cache

      public Cache(int maxSize, boolean useSynchronized)
    • Cache

      public Cache(int maxSize, boolean useSynchronized, boolean accessOrder)
      Parameters:
      maxSize - 最大容量
      useSynchronized - 是否使用同步
      accessOrder - 使用 LRU 策略
  • Method Details

    • get

      public V get(K key)
      Specified by:
      get in interface ICache<K,V>
    • put

      public V put(K key, V value)
      Specified by:
      put in interface ICache<K,V>
    • remove

      public V remove(K key)
      Specified by:
      remove in interface ICache<K,V>
    • clear

      public void clear()
      Specified by:
      clear in interface ICache<K,V>
    • computeIfAbsent

      public V computeIfAbsent(K key, Function<? super K,? extends V> mappingFunction)
      Specified by:
      computeIfAbsent in interface ICache<K,V>