Package org.apache.hadoop.util
Class LightWeightCache<K,E extends K>
java.lang.Object
org.apache.hadoop.util.LightWeightGSet<K,E>
org.apache.hadoop.util.LightWeightCache<K,E>
- Type Parameters:
K- Key type for looking up the entriesE- Entry type, which must be (1) a subclass of K, and (2) implementingLightWeightCache.Entryinterface, and
A low memory footprint Cache which extends
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.-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class org.apache.hadoop.util.LightWeightGSet
LightWeightGSet.LinkedElement, LightWeightGSet.SetIterator -
Field Summary
Fields inherited from class org.apache.hadoop.util.LightWeightGSet
entries, hash_mask, modification, size -
Constructor Summary
ConstructorsConstructorDescriptionLightWeightCache(int recommendedLength, int sizeLimit, long creationExpirationPeriod, long accessExpirationPeriod) -
Method Summary
Methods inherited from class org.apache.hadoop.util.LightWeightGSet
actualArrayLength, clear, computeCapacity, contains, convert, getIndex, printDetails, remove, size, toString, valuesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
LightWeightCache
public LightWeightCache(int recommendedLength, int sizeLimit, long creationExpirationPeriod, long accessExpirationPeriod) - Parameters:
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.
-
-
Method Details
-
get
Description copied from interface:GSetReturn the stored element which is equal to the given key. This operation is similar toMap.get(Object). -
put
Description copied from interface:GSetAdd/replace an element. If the element does not exist, add it to the set. Otherwise, replace the existing element. Note that this operation is similar toMap.put(Object, Object)but is different fromSet.add(Object)which does not replace the existing element if there is any. -
remove
Description copied from interface:GSetRemove the element corresponding to the given key. This operation is similar toMap.remove(Object). -
iterator
-