Package com.pnfsoftware.jeb.util.collect
Class CacheMap<K,V>
java.lang.Object
com.pnfsoftware.jeb.util.collect.CacheMap<K,V>
- Type Parameters:
K- key typeV- value type
A simple
CacheMap, with optional support for cached entries ordering.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Remove all cached entries.booleancontainsKey(K key) Determine whether a key is cached.Retrieve a cached entry.keys()Add or replace a cached entry.Remove a cached entry.booleanremoveRange(K fromKey, K toKey) intsize()Get the current cache size.
-
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 mapevictSize- number of objects evicted during a partial cache cleanupordered- 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 mapevictSize- 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
Add or replace a cached entry.- Parameters:
key- keyval- value- Returns:
- previous value, or null
-
get
Retrieve a cached entry.- Parameters:
key- key- Returns:
- cached value, or null if absent
-
containsKey
Determine whether a key is cached.- Parameters:
key- key- Returns:
- true if the key is cached
-
keys
- Returns:
- a copy of the cache keys (the client may modify the returned set, it will not impact the cache)
-
remove
Remove a cached entry.- Parameters:
key- key- Returns:
- removed value, or null
-
removeRange
- Parameters:
fromKey- start of rangetoKey- end of range (exclusive)- Returns:
- true if some entries were removed
-