K
- Key type for looking up the entriesE
- Entry type, which must be
(1) a subclass of K, and
(2) implementing LightWeightCache.Entry
interface, and@InterfaceAudience.Private public class LightWeightCache<K,E extends K> extends LightWeightGSet<K,E>
LightWeightGSet
.
An entry in the cache is expired if
(1) it is added to the cache longer than the creation-expiration period, and
(2) it is not accessed for the access-expiration period.
When an entry is expired, it may be evicted from the cache.
When the size limit of the cache is set, the cache will evict the entries
with earliest expiration time, even if they are not expired.
It is guaranteed that number of entries in the cache is less than or equal
to the size limit. However, It is not guaranteed that expired entries are
evicted from the cache. An expired entry may possibly be accessed after its
expiration time. In such case, the expiration time may be updated.
This class does not support null entry.
This class is not thread safe.Modifier and Type | Class and Description |
---|---|
static interface |
LightWeightCache.Entry
Entries of
LightWeightCache . |
LightWeightGSet.LinkedElement
Constructor and Description |
---|
LightWeightCache(int recommendedLength,
int sizeLimit,
long creationExpirationPeriod,
long accessExpirationPeriod) |
Modifier and Type | Method and Description |
---|---|
E |
get(K key)
Return the stored element which is equal to the given key.
|
E |
put(E entry)
Add/replace an element.
|
E |
remove(K key)
Remove the element corresponding to the given key.
|
clear, computeCapacity, contains, iterator, printDetails, size, toString
public LightWeightCache(int recommendedLength, int sizeLimit, long creationExpirationPeriod, long accessExpirationPeriod)
recommendedLength
- Recommended size of the internal array.sizeLimit
- the limit of the size of the cache.
The limit is disabled if it is <= 0.creationExpirationPeriod
- the time period C > 0 in nanoseconds that
the creation of an entry is expired if it is added to the cache
longer than C.accessExpirationPeriod
- the time period A >= 0 in nanoseconds that
the access of an entry is expired if it is not accessed
longer than A.public E get(K key)
GSet
Map.get(Object)
.public E put(E entry)
GSet
Map.put(Object, Object)
but is different from Set.add(Object)
which does not replace the existing element if there is any.public E remove(K key)
GSet
Map.remove(Object)
.Copyright © 2013 Apache Software Foundation. All rights reserved.