K
- the type of keys maintained by this cacheV
- the type of mapped valuespublic class SimpleLruCache<K,V> extends Object
Constructor and Description |
---|
SimpleLruCache(int maxSize,
float purgeFactor)
Create a new cache
|
Modifier and Type | Method and Description |
---|---|
void |
configure(int maxSize,
float purgeFactor)
Reconfigures the cache.
|
V |
get(Object key)
Returns the value to which the specified key is mapped, or
null
if this map contains no mapping for the key. |
V |
put(K key,
V value)
Maps the specified key to the specified value in this cache.
|
int |
size()
Returns the current size of this cache
|
public SimpleLruCache(int maxSize, float purgeFactor)
maxSize
- maximum size of the cache, to reduce need for synchronization
this is not a hard limit. The real size of the cache could be
slightly above this maximum if multiple threads put new values
concurrentlypurgeFactor
- when the size of the map reaches maxSize the oldest entries
will be purged to free up some space for new entries,
purgeFactor
is the fraction of maxSize
to
purge when this happenspublic V get(Object key)
null
if this map contains no mapping for the key.
More formally, if this cache contains a mapping from a key k
to a
value v
such that key.equals(k)
, then this method returns
v
; otherwise it returns null
. (There can be at most one
such mapping.)
key
- the keynull
if no value is mappedNullPointerException
- if the specified key is nullpublic V put(@NonNull K key, @NonNull V value)
The value can be retrieved by calling the get
method with a key
that is equal to the original key.
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified keykey
, or null
if there was no mapping for key
NullPointerException
- if the specified key or value is nullpublic int size()
public void configure(int maxSize, float purgeFactor)
maxSize
is reduced some entries will
be purged.maxSize
- maximum size of the cachepurgeFactor
- when the size of the map reaches maxSize the oldest entries
will be purged to free up some space for new entries,
purgeFactor
is the fraction of maxSize
to
purge when this happensCopyright © 2019 Eclipse JGit Project. All rights reserved.