|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.dasein.util.ConcurrentMultiCache<T>
T - the type for objects being stored in instances of the cachepublic class ConcurrentMultiCache<T>
A concurrent multi-cache caches objects along multiple unique keys. You provide the list of unique keys and then this object will manage the concurrent access of multiple threads into the cache.
This class is backed up by multiple @{link ConcurrentCache} instances (one for each unique key) and thus behaves in accordance with the rules for that object. If, for example, you wanted to create a memory cache of employees:
public class EmployeeFactory {
private ConcurrentMultiCache<Employee> cache = new ConcurrentMultiCache<Employee>(Employee.class, "employeeId", "email");
public Employee getEmployeeById(Number id) {
return cache.find("employeeId", id, getIdLoader(id));
}
public Employee getEmployeeByEmail(String email) {
return cache.find("email", email, getEmailLoader(email));
}
}
In the above example, the getIdLoader() and getEmailLoader()
methods would be methods you would create to return an instance of
CacheLoader that would load the desired employee from the database based
on the employee ID or email address, respectively.
Last modified: $Date: 2006/08/31 18:46:17 $
| Constructor Summary | |
|---|---|
ConcurrentMultiCache(Class<T> cls,
Collection<String> attrs)
Constructs a concurrent multi-cache that caches for unique keys specified by the attributes. |
|
ConcurrentMultiCache(Class<T> cls,
String... attrs)
Constructs a concurrent multi-cache that caches for unique keys specified by the attributes. |
|
ConcurrentMultiCache(String... attrs)
Constructs a concurrent multi-cache that caches for unique keys specified by the attributes. |
|
| Method Summary | |
|---|---|
T |
cache(T item)
Places the specified item in the cache. |
T |
find(Map<String,Object> vals)
Finds the object in the cache matching the values in the specified value map. |
T |
find(Object val)
Finds the object from the cache with the specified unique identifier value for the default unique identifier attribute. |
T |
find(Object val,
CacheLoader<T> loader)
Calls find(String,Object,CacheLoader) using the only unique
identifier attribute as passed to this cache's constructor. |
T |
find(String key,
Object val)
Returns the object identified by the specified key/value pair if it is currently in memory in the cache. |
T |
find(String key,
Object val,
CacheLoader<T> loader)
Seeks the item from the cache that is identified by the specified key having the specified value. |
T |
find(String key,
Object val,
CacheLoader<T> loader,
Object... args)
Seeks the item from the cache that is identified by the specified key having the specified value. |
HashMap<String,Object> |
getKeys(T item)
Provides the values for all of the unique identifiers managed by the cache. |
Class<T> |
getTarget()
|
void |
release(T item)
Releases the specified item from the cache. |
String |
toString()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public ConcurrentMultiCache(Class<T> cls,
Collection<String> attrs)
cls - the class object for objects stored in this cacheattrs - the unique keys that this cache will cache objects onpublic ConcurrentMultiCache(String... attrs)
attrs - the unique keys that this cache will cache objects on
public ConcurrentMultiCache(Class<T> cls,
String... attrs)
cls - the class object for objects stored in this cacheattrs - the unique keys that this cache will cache objects on| Method Detail |
|---|
public T cache(T item)
item - the item to be cached
public T find(Object val)
val - the value matching the desired object from the cache
CacheManagementException - this multi-cache supports multiple unique IDspublic T find(Map<String,Object> vals)
vals - the mapping that includes the attribute/value pairs
public T find(String key,
Object val)
null does
not mean the object does not exist. Instead, it may be that it is simply not
cached in memory.
key - they unique identifier attribute on which you are searchingval - the value of the unique identifier on which you are searching
public T find(Object val,
CacheLoader<T> loader)
find(String,Object,CacheLoader) using the only unique
identifier attribute as passed to this cache's constructor. If more than one
unique identifier attribute was passed, this method will throw an exception
val - the value of the unique key being soughtloader - the loader to load new instances from the persistent store
CacheManagementException - this cache supports multiple unique identifiers
public T find(String key,
Object val,
CacheLoader<T> loader)
null for the loader.
If you do, only an object in active memory will be returned.
key - the name of the unique identifier attribute whose value you haveval - the value of the unique identifier that identifiers the desired itemloader - a loader to load the desired object from the persistence store if it
is not in memory
public T find(String key,
Object val,
CacheLoader<T> loader,
Object... args)
key - the name of the unique identifier attribute whose value you haveval - the value of the unique identifier that identifiers the desired itemloader - a loader to load the desired object from the persistence store if it
is not in memoryargs - any arguments to pass to the loader
public HashMap<String,Object> getKeys(T item)
item - the item whose key values are being sought
public Class<T> getTarget()
public void release(T item)
null.
item - the item to be released from the cache.public String toString()
toString in class Object
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||