|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--com.go.trove.util.Depot
Depot implements a simple and efficient caching strategy. It is thread-safe, and it allows requests of different objects to occur concurrently. Depot is best suited as a front-end for accessing objects from a remote device, like a database. If the remote device is not responding, the Depot will continue to serve invalidated objects so that the requester may continue as normal.
Depot is designed as a cache in front of an object factory.
Objects may be invalidated, but they are not explicitly removed from the
cache until a replacement has been provided by the factory. The factory is
invoked from another thread, allowing for the requester to timeout and use
an invalidated object. When the factory eventually finishes, its object will
be cached.
By allowing for eventual completion of the factory, Depot enables applications to dynamically adjust to the varying performance and reliability of remote data providers.
Depot will never return an object or null that did not originate from the factory. When retrieving an object that wasn't found cached, a call to the factory will block until it is finished.
Objects may be invalided from the Depot
automatically. This approach is based on a fixed
time expiration and is somewhat inflexible. An ideal invalidation strategy
requires asynchronous notification from the actual data providers.
MultiKey| Inner Class Summary | |
static interface |
Depot.Factory
Implement this interface in order for Depot to retrieve objects when needed, often in a thread other than the requester's. |
static interface |
Depot.Filter
|
static interface |
Depot.Perishable
Values returned from the Factories may implement this interface if they manually handle expiration. |
static interface |
Depot.PerishablesFactory
A special kind of Factory that creates objects that are considered invalid after a specific amount of time has elapsed. |
| Constructor Summary | |
Depot(Depot.Factory factory,
int cacheSize,
TransactionQueue tq,
long timeout)
|
|
Depot(Depot.Factory factory,
java.util.Map validCache,
java.util.Map invalidCache,
TransactionQueue tq,
long timeout)
|
|
| Method Summary | |
void |
clear()
Completely removes all items from the Depot's caches. |
java.lang.Object |
get(Depot.Factory factory,
java.lang.Object key)
Retrieve an object from the Depot. |
java.lang.Object |
get(Depot.Factory factory,
java.lang.Object key,
long timeout)
Retrieve an object from the Depot. |
java.lang.Object |
get(java.lang.Object key)
Retrieve an object from the Depot. |
java.lang.Object |
get(java.lang.Object key,
long timeout)
Retrieve an object from the Depot. |
void |
invalidate(java.lang.Object key)
Invalidate the object referenced by the given key, if it is already cached in this Depot. |
void |
invalidateAll()
Invalidates all the objects in the Depot. |
void |
invalidateAll(Depot.Filter filter)
Invalidates objects in the Depot, using a filter. |
int |
invalidSize()
Returns the number of invalid objects in the Depot. |
boolean |
isEmpty()
|
void |
put(java.lang.Object key,
java.lang.Object value)
Put a value into the Depot, bypassing the factory. |
java.lang.Object |
remove(java.lang.Object key)
Completely removes an item from the Depot's caches. |
void |
removeAll(Depot.Filter filter)
Completely removes all the items from the Depot that the given filter accepts. |
int |
size()
Returns the total number objects in the Depot. |
int |
validSize()
Returns the number of valid objects in the Depot. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public Depot(Depot.Factory factory,
java.util.Map validCache,
java.util.Map invalidCache,
TransactionQueue tq,
long timeout)
factory - Default factory from which objects are obtainedvalidCache - Map to use for caching valid objectsinvalidCache - Map to use for caching invalid objectstq - TransactionQueue for scheduling factory invocations.timeout - Default timeout (in milliseconds) to apply to "get"
method.
public Depot(Depot.Factory factory,
int cacheSize,
TransactionQueue tq,
long timeout)
factory - Default factory from which objects are obtainedcacheSize - Number of items guaranteed to be in cache, if negative,
cache is completely disabled.tq - TransactionQueue for scheduling factory invocations.timeout - Default timeout (in milliseconds) to apply to "get"
method.| Method Detail |
public int size()
public boolean isEmpty()
public int validSize()
public int invalidSize()
public java.lang.Object get(java.lang.Object key)
key - key of object to retrieve
public java.lang.Object get(java.lang.Object key,
long timeout)
key - key of object to retrievetimeout - max time (in milliseconds) to wait for an invalid value
to be replaced from the factory, if negative, wait forever. Ignored if
no cached value exists at all.
public java.lang.Object get(Depot.Factory factory,
java.lang.Object key)
factory - factory to use to retrieve object if not cachedkey - key of object to retrieve
public java.lang.Object get(Depot.Factory factory,
java.lang.Object key,
long timeout)
factory - factory to use to retrieve object if not cachedkey - key of object to retrievetimeout - max time (in milliseconds) to wait for an invalid value
to be replaced from the factory, if negative, wait forever. Ignored if
no cached value exists at all.public void invalidate(java.lang.Object key)
key - key of object to invalidatepublic void invalidateAll(Depot.Filter filter)
public void invalidateAll()
public void put(java.lang.Object key,
java.lang.Object value)
key - key with which to associate the value.value - value to be associated with key.public java.lang.Object remove(java.lang.Object key)
public void removeAll(Depot.Filter filter)
public void clear()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||