Class CacheMap<K,V>

java.lang.Object
com.pnfsoftware.jeb.util.collect.CacheMap<K,V>
Type Parameters:
K - key type
V - value type

public class CacheMap<K,V> extends Object
A simple CacheMap, with optional support for cached entries ordering.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
     
    int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    CacheMap(int maxSize)
    Construct a cache map with an eviction size equals to 25% of the cache size.
    CacheMap(int maxSize, int evictSize)
    Construct a cache map.
    CacheMap(int maxSize, int evictSize, boolean ordered)
    Construct a cache map.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Remove all cached entries.
    boolean
    Determine whether a key is cached.
    get(K key)
    Retrieve a cached entry.
     
    put(K key, V val)
    Add or replace a cached entry.
    remove(K key)
    Remove a cached entry.
    boolean
    removeRange(K fromKey, K toKey)
     
    int
    Get the current cache size.

    Methods inherited from class java.lang.Object

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

    • dbgQueryCount

      public int dbgQueryCount
    • dbgHitCount

      public int dbgHitCount
  • Constructor Details

    • CacheMap

      public CacheMap(int maxSize, int evictSize, boolean ordered)
      Construct a cache map. Whenever an element is added and the map exceeds the maximum size, it will be partially cleaned up by evicting the last accessed objects.
      Parameters:
      maxSize - maximum size of the cache map
      evictSize - number of objects evicted during a partial cache cleanup
      ordered - true to naturally order elements in the map
    • CacheMap

      public CacheMap(int maxSize, int evictSize)
      Construct a cache map. Whenever an element is added and the map exceeds the maximum size, it will be partially cleaned up by evicting the last accessed objects.
      Parameters:
      maxSize - maximum size of the cache map
      evictSize - number of objects evicted during a partial cache cleanup
    • CacheMap

      public CacheMap(int maxSize)
      Construct a cache map with an eviction size equals to 25% of the cache size.
      Parameters:
      maxSize - maximum size of the map
  • Method Details

    • size

      public int size()
      Get the current cache size.
      Returns:
      number of cached entries
    • clear

      public void clear()
      Remove all cached entries.
    • put

      public V put(K key, V val)
      Add or replace a cached entry.
      Parameters:
      key - key
      val - value
      Returns:
      previous value, or null
    • get

      public V get(K key)
      Retrieve a cached entry.
      Parameters:
      key - key
      Returns:
      cached value, or null if absent
    • containsKey

      public boolean containsKey(K key)
      Determine whether a key is cached.
      Parameters:
      key - key
      Returns:
      true if the key is cached
    • keys

      public Set<K> keys()
      Returns:
      a copy of the cache keys (the client may modify the returned set, it will not impact the cache)
    • remove

      public V remove(K key)
      Remove a cached entry.
      Parameters:
      key - key
      Returns:
      removed value, or null
    • removeRange

      public boolean removeRange(K fromKey, K toKey)
      Parameters:
      fromKey - start of range
      toKey - end of range (exclusive)
      Returns:
      true if some entries were removed