Class ConcurrentLruCache<K,V>

java.lang.Object
com.alibaba.druid.util.ConcurrentLruCache<K,V>

public final class ConcurrentLruCache<K,V> extends Object
Simple LRU (Least Recently Used) cache, bounded by a specified cache capacity. This is a simplified, opinionated implementation of an LRU cache It is inspired from ConcurrentLruCache.
  • Constructor Details

    • ConcurrentLruCache

      public ConcurrentLruCache(int capacity)
  • Method Details

    • get

      public V get(K key)
    • computeIfAbsent

      public V computeIfAbsent(K key, Function<K,V> generator)
    • forEach

      public void forEach(BiConsumer<K,V> action)
    • keys

      public Set<K> keys()
    • size

      public int size()
    • clear

      public void clear()
    • contains

      public boolean contains(K key)
      Determine whether the given key is present in this cache.
      Parameters:
      key - the key to check for
      Returns:
      true if the key is present, false if there was no matching key
    • remove

      public boolean remove(K key)
      Immediately remove the given key and any associated value.
      Parameters:
      key - the key to evict the entry for
      Returns:
      true if the key was present before, false if there was no matching key