|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--com.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.
| 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 | |
java.lang.Object |
get(java.lang.Object key)
Returns an object from the cache, if it exists and hasn't expired. |
static java.lang.Object |
getGlobal(java.lang.Object key)
Returns an object from the global cache, if it exists and hasn't expired. |
static void |
main(java.lang.String[] args)
|
void |
put(java.lang.Object key,
java.lang.Object value)
Puts a new key/value pair into the cache with default lifetime (this.maxAge). |
void |
put(java.lang.Object key,
java.lang.Object value,
long maxAge)
Puts a new key/value pair into the cache. |
static void |
putGlobal(java.lang.Object key,
java.lang.Object value)
Puts a new key/value pair into the static global cache with default lifetime. |
static void |
putGlobal(java.lang.Object key,
java.lang.Object value,
long maxAge)
Puts a new key/value pair into the static global cache with specified lifetime. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Cache(long size)
size - the number of items to allow before eviction
public 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(java.lang.Object key,
java.lang.Object value)
key - the keyvalue - the value
public void put(java.lang.Object key,
java.lang.Object value,
long maxAge)
key - the keyvalue - the valuemaxAge - the maximum lifetime of this cache entry, in
millisecondspublic java.lang.Object get(java.lang.Object key)
key - the key to look upkey, or null
public static void putGlobal(java.lang.Object key,
java.lang.Object value)
key - the keyvalue - the value
public static void putGlobal(java.lang.Object key,
java.lang.Object value,
long maxAge)
key - the keyvalue - the valuemaxAge - the lifetime of this cache entry in mspublic static java.lang.Object getGlobal(java.lang.Object key)
key - the key to look upkey, or null
public static void main(java.lang.String[] args)
throws java.lang.Exception
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||