|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.hadoop.hive.ql.util.jdbm.helper.SoftCache
public class SoftCache
Wraps a deterministic cache policy with a Level-2
cache based on
J2SE's soft references
. Soft references allow this
cache to keep references to objects until the memory they occupy is required
elsewhere.
Since the CachePolicy
interface requires an event be fired when an
object is evicted, and the event contains the actual object, this class
cannot be a stand-alone implementation of CachePolicy
. This
limitation arises because Java References does not support notification
before references are cleared; nor do they support reaching soft referents.
Therefore, this wrapper cache aggressively notifies evictions: events are
fired when the objects are evicted from the internal cache. Consequently, the
soft cache may return a non-null object when get( )
is called,
even if that object was said to have been evicted.
The current implementation uses a hash structure for its internal key to value mappings.
Note: this component's publicly exposed methods are not threadsafe; potentially concurrent code should synchronize on the cache instance.
Constructor Summary | |
---|---|
SoftCache()
Creates a soft-reference based L2 cache with a MRU cache as the
internal (L1) cache. |
|
SoftCache(CachePolicy internal)
Creates a soft-reference based L2 cache wrapping the specified L1 cache. |
|
SoftCache(float loadFactor,
CachePolicy internal)
Creates a soft-reference based L2 cache wrapping the specified L1 cache. |
Method Summary | |
---|---|
void |
addListener(CachePolicyListener listener)
Adds the specified listener to this cache. |
Enumeration |
elements()
Gets all the objects stored by the internal (L1) cache. |
Object |
get(Object key)
Gets the object cached under the specified key. |
void |
put(Object key,
Object value)
Adds the specified value to the cache under the specified key. |
void |
remove(Object key)
Removes any object stored under the key specified. |
void |
removeAll()
Removes all objects in this (L2) and its internal (L1) cache. |
void |
removeListener(CachePolicyListener listener)
Removes a listener that was added earlier. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SoftCache()
MRU
cache as the
internal (L1) cache. The soft reference cache uses the default load
capacity of 1.5f, which is intended to sacrifice some performance for
space. This compromise is reasonable, since all get(
)s
first try the L1 cache anyway. The internal MRU is given a capacity of
128 elements.
public SoftCache(CachePolicy internal) throws NullPointerException
internal
- non null internal cache.
NullPointerException
- if the internal cache is null.public SoftCache(float loadFactor, CachePolicy internal) throws IllegalArgumentException, NullPointerException
SoftCache(CachePolicy)
instead.
loadFactor
- load factor that the soft cache's hash structure should use.internal
- non null internal cache.
IllegalArgumentException
- if the load factor is nonpositive.
NullPointerException
- if the internal cache is null.Method Detail |
---|
public void put(Object key, Object value) throws CacheEvictionException
put
in interface CachePolicy
key
- the (non-null) key to store the object undervalue
- the (non-null) object to place in the cache
CacheEvictionException
- exception that the internal cache would have experienced while
evicting an object it currently cached.public Object get(Object key)
The cache is looked up in the following manner:
CachePolicy.put(Object, Object)
.
get
in interface CachePolicy
key
- the key that the object was stored under.
public void remove(Object key)
remove
in interface CachePolicy
key
- the key whose object should be removedpublic void removeAll()
removeAll
in interface CachePolicy
public Enumeration elements()
elements
in interface CachePolicy
public void addListener(CachePolicyListener listener) throws IllegalArgumentException
addListener
in interface CachePolicy
listener
- the (non-null) listener to add to this policy
IllegalArgumentException
- if listener is null.public void removeListener(CachePolicyListener listener)
removeListener
in interface CachePolicy
listener
- the listener to remove.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |