T
- value type@ThreadSafe public final class FIFOCache<T> extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private BoundedLinkedHashMap<java.lang.String,T> |
map |
private java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock |
rlock |
private java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock |
wlock |
Constructor and Description |
---|
FIFOCache(int maxSize) |
Modifier and Type | Method and Description |
---|---|
T |
add(java.lang.String key,
T value)
Adds an entry to the cache, evicting the earliest entry if necessary.
|
T |
get(java.lang.String key)
Returns the value of the given key; or null of no such entry exists.
|
int |
getMaxSize()
Returns the maximum size of the cache.
|
int |
size()
Returns the current size of the cache.
|
java.lang.String |
toString() |
private final BoundedLinkedHashMap<java.lang.String,T> map
private final java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock rlock
private final java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock wlock
public FIFOCache(int maxSize)
maxSize
- the maximum number of entries of the cachepublic T add(java.lang.String key, T value)
public T get(java.lang.String key)
public int size()
public int getMaxSize()
public java.lang.String toString()
toString
in class java.lang.Object