|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.arsdigita.util.Cache
data structure for a fixed-size cache table. Note that Cache is not thread-safe; it is up to the caller to synchronize if a cache is shared across multiple threads. Also includes a static global cache, whose methods are threadsafe.
Field Summary | |
static String |
versionId
|
Constructor Summary | |
Cache(long size)
Create a new Cache of a fixed size. |
|
Cache(long size,
long maxAge)
Create a new Cache of a fixed size. |
Method Summary | |
void |
clear()
Removes all mapping from this map |
Object |
get(Object key)
Returns an object from the cache, if it exists and hasn't expired. |
static Object |
getGlobal(Object key)
Returns an object from the global cache, if it exists and hasn't expired. |
void |
put(Object key,
Object value)
Puts a new key/value pair into the cache with default lifetime (this.maxAge). |
void |
put(Object key,
Object value,
long maxAge)
Puts a new key/value pair into the cache. |
static void |
putGlobal(Object key,
Object value)
Puts a new key/value pair into the static global cache with default lifetime. |
static void |
putGlobal(Object key,
Object value,
long maxAge)
Puts a new key/value pair into the static global cache with specified lifetime. |
void |
remove(Object key)
Removes the mapping for this key if it exists |
static void |
removeGlobal(Object key)
Removes the mapping for this key if it exists |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String versionId
Constructor Detail |
public Cache(long size)
size
- the number of items to allow before evictionpublic Cache(long size, long maxAge)
Also allows an expiration time to be set; items in the cache that are older than that time will be evicted.
size
- the number of items to allow before evictionmaxAge
- the longest period of time, in milliseconds, that
an element may stay in the cache before it is evicted, by default.
(may be overriden by put).Method Detail |
public void put(Object key, Object value)
key
- the keyvalue
- the valuepublic void put(Object key, Object value, long maxAge)
key
- the keyvalue
- the valuemaxAge
- the maximum lifetime of this cache entry, in
millisecondspublic Object get(Object key)
key
- the key to look up
key
, or nullpublic void remove(Object key)
key
- key whose mapping is to be removedpublic void clear()
public static void putGlobal(Object key, Object value)
key
- the keyvalue
- the valuepublic static void putGlobal(Object key, Object value, long maxAge)
key
- the keyvalue
- the valuemaxAge
- the lifetime of this cache entry in mspublic static void removeGlobal(Object key)
key
- key whose mapping is to be removedpublic static Object getGlobal(Object key)
key
- the key to look up
key
, or null
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |