Package alpine.cache
Class AbstractCacheManager
- java.lang.Object
-
- alpine.cache.AbstractCacheManager
-
- Direct Known Subclasses:
CacheManager
public abstract class AbstractCacheManager extends Object
AbstractCacheManager provides a per-class object cache.- Since:
- 1.5.0
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractCacheManager(long expiresAfter, TimeUnit timeUnit, long maxSize)Constructs a new AbstractCacheManager object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> Tget(Class clazz, String key)Retrieves an object (of the specified class) from cache.<T> Tget(Class clazz, String key, Function mappingFunction)Retrieves an object (of the specified class) from cache.voidmaintenance(Class clazz)Performs maintenance on the cache.voidput(String key, Object object)Adds an object to cache.voidremove(Class clazz, String key)Remove an object from cache.
-
-
-
Constructor Detail
-
AbstractCacheManager
protected AbstractCacheManager(long expiresAfter, TimeUnit timeUnit, long maxSize)Constructs a new AbstractCacheManager object.- Parameters:
expiresAfter- the number of time units to expire aftertimeUnit- the unit of measurementmaxSize- the maximum size of the cache (per object type)
-
-
Method Detail
-
get
public <T> T get(Class clazz, String key)
Retrieves an object (of the specified class) from cache.- Type Parameters:
T- the object type- Parameters:
clazz- the class of the object to retrieve from cachekey- the unique identifier of the object to retrieve from cache- Returns:
- the cached object (if found) or null if not found
- Since:
- 1.5.0
-
get
public <T> T get(Class clazz, String key, Function mappingFunction)
Retrieves an object (of the specified class) from cache.- Type Parameters:
T- the object type- Parameters:
clazz- the class of the object to retrieve from cachekey- the unique identifier of the object to retrieve from cachemappingFunction- the function to call if the object is not present in cache- Returns:
- the cached object (if found) or null if not found and a mappingFunction is not specified
- Since:
- 1.5.0
-
put
public void put(String key, Object object)
Adds an object to cache.- Parameters:
key- the unique identifier of the object to put into cacheobject- the object to put into cache.- Since:
- 1.5.0
-
remove
public void remove(Class clazz, String key)
Remove an object from cache.- Parameters:
clazz- the class of the object to remove from cachekey- the unique identifier of the object to remove from cache
-
maintenance
public void maintenance(Class clazz)
Performs maintenance on the cache. Maintenance is automatically carried out and use of this method is normally not required. However, if maintenance must be performed immediately, use of this method may be called.- Parameters:
clazz- the class of the object to perform maintenance on- Since:
- 1.5.0
-
-