Package com.priint.pubserver.util
Class LimitedCache<T>
java.lang.Object
com.priint.pubserver.util.LimitedCache<T>
- Type Parameters:
T-
A 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
ConstructorsConstructorDescriptionLimitedCache(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
Modifier and TypeMethodDescriptionvoidclear()Remove all data from cache.booleancontainsKey(String key) Returns true if this map contains a mapping for the specified key.Retrieve a value.voidAdd a value.Remove a value.intsize()Returns the number of key-value mappings in this cache.
-
Constructor Details
-
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 Details
-
put
Add a value.- Parameters:
key-value-
-
get
Retrieve a value.- Parameters:
key-- Returns:
-
remove
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
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:
-