|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.octo.android.robospice.persistence.CacheManager
public class CacheManager
An entity responsible for loading/saving data from/to cache. It implements a
Chain of Responsibility pattern, delegating loading and saving operations to
ObjectPersister
or ObjectPersisterFactory
elements. The chain
of responsibility is ordered. This means that the order used to register
elements matters. All elements in the chain of responsibility are questioned
in order. The first element that can handle a given class for persistence
will be used to persist data of this class.
Constructor Summary | |
---|---|
CacheManager()
|
Method Summary | ||
---|---|---|
void |
addPersister(Persister persister)
|
|
|
getAllCacheKeys(Class<T> clazz)
Get all cache keys associated to a given class. |
|
Date |
getDateOfDataInCache(Class<?> clazz,
Object cacheKey)
The date at which given data has been stored last in cache. |
|
protected
|
getObjectPersister(Class<T> clazz)
|
|
boolean |
isDataInCache(Class<?> clazz,
Object cacheKey,
long maxTimeInCacheBeforeExpiry)
Test whether or not some data is in cache. |
|
|
loadAllDataFromCache(Class<T> clazz)
Loads all data stored in cache for a given class. |
|
|
loadDataFromCache(Class<T> clazz,
Object cacheKey,
long maxTimeInCacheBeforeExpiry)
Loads an instance of a class clazz, that is stored in cache under the key cacheKey. |
|
void |
removeAllDataFromCache()
Removes all data in the cache. |
|
void |
removeAllDataFromCache(Class<?> clazz)
Removes all data in the cache that are instances of class clazz. |
|
boolean |
removeDataFromCache(Class<?> clazz,
Object cacheKey)
Removes a given data in the cache that is an instance of class clazz. |
|
void |
removePersister(Persister persister)
|
|
|
saveDataToCacheAndReturnData(T data,
Object cacheKey)
Save an instance of a given class, into the cache identified by cacheKey. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public CacheManager()
Method Detail |
---|
public void addPersister(Persister persister)
addPersister
in interface ICacheManager
public void removePersister(Persister persister)
removePersister
in interface ICacheManager
public <T> T loadDataFromCache(Class<T> clazz, Object cacheKey, long maxTimeInCacheBeforeExpiry) throws CacheLoadingException, CacheCreationException
loadDataFromCache
in interface ICacheManager
clazz
- the class of the object that is supposed to be stored in
cache.cacheKey
- the key used to identify this item in cache.maxTimeInCacheBeforeExpiry
- the maximum time (in ms) an item can be stored in cache before
being considered expired.
CacheCreationException
CacheLoadingException
public <T> T saveDataToCacheAndReturnData(T data, Object cacheKey) throws CacheSavingException, CacheCreationException
ICacheManager
ObjectPersister
can modify the data they receive before
saving it. Most ObjectPersister
instances will just save the data
as-is, in this case, they can even return it and save it asynchronously
in a background thread for a better efficiency.
saveDataToCacheAndReturnData
in interface ICacheManager
data
- the data to be saved in cache.cacheKey
- the key used to identify this item in cache.
CacheSavingException
CacheCreationException
public boolean isDataInCache(Class<?> clazz, Object cacheKey, long maxTimeInCacheBeforeExpiry) throws CacheCreationException
isDataInCache
in interface ICacheManager
clazz
- the class of the object that is supposed to be stored in
cache.cacheKey
- the key used to identify this item in cache.maxTimeInCacheBeforeExpiry
- the maximum time (in ms) an item can be stored in cache before
being considered expired.
CacheCreationException
public Date getDateOfDataInCache(Class<?> clazz, Object cacheKey) throws CacheLoadingException, CacheCreationException
getDateOfDataInCache
in interface ICacheManager
clazz
- the class of the object that is supposed to be stored in
cache.cacheKey
- the key used to identify this item in cache.
CacheLoadingException
CacheCreationException
public boolean removeDataFromCache(Class<?> clazz, Object cacheKey)
removeDataFromCache
in interface ICacheManager
clazz
- the class of the data to be removed.cacheKey
- the identifier of the data to be removed from cache.
public void removeAllDataFromCache(Class<?> clazz)
removeAllDataFromCache
in interface ICacheManager
clazz
- the class of the data to be removed.public <T> List<Object> getAllCacheKeys(Class<T> clazz)
getAllCacheKeys
in interface ICacheManager
clazz
- the class for which to get all cache keys.
public <T> List<T> loadAllDataFromCache(Class<T> clazz) throws CacheLoadingException, CacheCreationException
loadAllDataFromCache
in interface ICacheManager
clazz
- the class for which to get all data stored in cache.
CacheCreationException
CacheLoadingException
public void removeAllDataFromCache()
removeAllDataFromCache
in interface ICacheManager
protected <T> ObjectPersister<T> getObjectPersister(Class<T> clazz) throws CacheCreationException
CacheCreationException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |