|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfc.util.cache.BoundedCache
public final class BoundedCache
In memory cache with the ability to specify an item bound/cache-limit functionality. By default,the upper bound is Integer.MAX_VALUE.
Existing items are not automatically expired. They are only removed when a new item is added and the bound size is crossed. Which item is removed is according to BoundedCache.POLICY.
ThreadSafety: This class is thread safe and can be used by multiple threads concurrently.
Nested Class Summary | |
---|---|
static class |
BoundedCache.Policy
least_used, fifo |
Constructor Summary | |
---|---|
BoundedCache(BoundedCache.Policy cachePolicy,
int bound)
Creates a memory cache with a system-assigned name, logger and the specified policy and bound. |
|
BoundedCache(Log log,
java.lang.String name,
BoundedCache.Policy cachePolicy,
int bound)
Instantiates this class with the specified name, logger, policy and cache size. |
Method Summary | |
---|---|
void |
clear()
|
void |
close()
Closes this cache, which makes all items in the cache unavailable. |
java.lang.Object |
containsKey(java.lang.Object key)
Returns the item for the specified key or null if the item does not exist. |
void |
expire(java.lang.Object key)
Removes the object specified by the key. |
java.lang.Object |
get(java.lang.Object key)
Returns the item for the specified key or null if the item does not exist. |
java.util.Map |
getAll()
Returns the underlying storage read-only map for this cache. |
long |
getBound()
Gets the current bound of this cache. |
boolean |
isClosed()
Returns true if this cache has been closed, false otherwise. |
static void |
main(java.lang.String[] args)
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object val)
Puts the item for the specified key. |
void |
setBound(int items)
Sets the upper bound of this cache. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public BoundedCache(Log log, java.lang.String name, BoundedCache.Policy cachePolicy, int bound)
name
- String denoting the name for this objectlogger
- a reference to a Log
cachePolicy
- item removal policy when cache is fullbound
- the upper bound of this cache.public BoundedCache(BoundedCache.Policy cachePolicy, int bound)
Method Detail |
---|
public void setBound(int items)
public long getBound()
public void expire(java.lang.Object key)
public java.lang.Object containsKey(java.lang.Object key)
public java.lang.Object get(java.lang.Object key)
public java.util.Map getAll()
public java.lang.Object put(java.lang.Object key, java.lang.Object val)
public void close()
Note:, it is a good idea to close the cache once it's not needed, because it releases resources, including any internal threads spawned and used by this implementation.
public boolean isClosed()
public void clear()
public java.lang.String toString()
toString
in class java.lang.Object
public static void main(java.lang.String[] args)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |