public class Cache
extends java.lang.Object
Store| Constructor and Description |
|---|
Cache(Store store)
Initialize a cache using the specified backing store.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Removes all entries from the cache.
|
java.lang.Object |
getIfPinned(java.lang.Object key)
Return the value stored for the given key from the cache.
|
java.lang.Object |
pin(java.lang.Object key)
Returns an object from the cache.
|
java.lang.Object |
pin(java.lang.Object key,
java.lang.Object o)
Adds a key-value pair to the cache.
|
java.lang.Object |
putIfAbsent(java.lang.Object key,
java.lang.Object newObj)
Adds a key-value pair to the cache.
|
int |
size()
Returns the number of entries in the cache.
|
java.lang.Object |
unpin(java.lang.Object key)
Removes the entry for the given key from the cache.
|
public Cache(Store store)
store - The backing store.public java.lang.Object getIfPinned(java.lang.Object key)
key - The key for the object to look up in the cache.getIfPinned does not call Store.load(java.lang.Object).Store.load(java.lang.Object)public java.lang.Object unpin(java.lang.Object key)
key - The key for the entry to remove.null.public void clear()
public int size()
public java.lang.Object pin(java.lang.Object key,
java.lang.Object o)
pin does not call Store.load(java.lang.Object) to retrieve
an entry from backing store if an entry for the given key is not yet in the cache. This
is useful to add a newly-created object to the cache.key - The key for the entry.o - The value for the entry.pin(Object, Object) returns the original value for the entry; otherwise,
the entry is added and pin(Object, Object) returns null.public java.lang.Object pin(java.lang.Object key)
pin calls
Store.load(java.lang.Object) to retrieve the corresponding value (if any) from the
backing store.key - The key for the entry to retrieve.pin(Object) calls
Store.load(java.lang.Object) and the return value is whatever is returned by
load; if load throws an exception, that exception
is thrown by pin(Object).public java.lang.Object putIfAbsent(java.lang.Object key,
java.lang.Object newObj)
key - The key for the entry.newObj - The value for the entry.putIfAbsent returns the original value for that key.
If no entry is for the given key is in the cache, putIfAbsent
calls Store.load(java.lang.Object) to retrieve the corresponding entry (if any) from
the backings store and returns the value returned by load.
If the cache does not contain an entry for the given key and load
does not return a value for the key, putIfAbsent adds the new entry
and returns null.