Package com.priint.pubserver.util
Class LimitedCache<T>
- java.lang.Object
-
- com.priint.pubserver.util.LimitedCache<T>
-
- Type Parameters:
T-
public class LimitedCache<T> extends java.lang.ObjectA simple cache limited by size and duration and backed by a HashMap.Poor man's version of some functionality in Guava's ConcurrentLinkedHashMap
This one does not hold an access count or latest access time.- Since:
- 4.1.5
-
-
Constructor Summary
Constructors Constructor Description LimitedCache(int maxItems)Create a cache with unlimited duration for items.LimitedCache(int maxItems, int maxSeconds)Create a cache with limited number of items and limited duration for items.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Remove all data from cache.booleancontainsKey(java.lang.String key)Returns true if this map contains a mapping for the specified key.Tget(java.lang.String key)Retrieve a value.voidput(java.lang.String key, T value)Add a value.Tremove(java.lang.String key)Remove a value.intsize()Returns the number of key-value mappings in this cache.
-
-
-
Constructor Detail
-
LimitedCache
public LimitedCache(int maxItems)
Create a cache with unlimited duration for items.- Parameters:
maxItems-
-
LimitedCache
public LimitedCache(int maxItems, int maxSeconds)Create a cache with limited number of items and limited duration for items.- Parameters:
maxItems- values smaller than 1 are interpreted as "no limit" for number.maxSeconds- values smaller than 1 are interpreted as "no limit" for duration.
-
-
Method Detail
-
put
public void put(java.lang.String key, T value)Add a value.- Parameters:
key-value-
-
get
public T get(java.lang.String key)
Retrieve a value.- Parameters:
key-- Returns:
-
remove
public T remove(java.lang.String key)
Remove a value.Non existing entries will be ignored and return NULL.
- Parameters:
key-- Returns:
- value of the remove entry
-
clear
public void clear()
Remove all data from cache.
-
containsKey
public boolean containsKey(java.lang.String key)
Returns true if this map contains a mapping for the specified key.- Returns:
-
size
public int size()
Returns the number of key-value mappings in this cache.- Returns:
-
-