Package de.caluga.morphium.cache
Class MorphiumCacheImpl
- java.lang.Object
-
- de.caluga.morphium.cache.MorphiumCacheImpl
-
- All Implemented Interfaces:
MorphiumCache
public class MorphiumCacheImpl extends Object implements MorphiumCache
User: Stephan Bösebeck Date: 07.03.13 Time: 10:56 The Cache implementation for morphium.
-
-
Constructor Summary
Constructors Constructor Description MorphiumCacheImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCacheListener(CacheListener cl)<T> voidaddToCache(String k, Class<? extends T> type, List<T> ret)adds some list of objects to the cache manually...voidclearCachefor(Class<?> cls)voidclearCacheIfNecessary(Class cls)voidclose()Map<Class<?>,Map<String,CacheEntry>>getCache()Set<Class<?>>getCachedTypes()StringgetCacheKey(Query q)create unique cache key for queries, also honoring skip & limit and sortingStringgetCacheKey(Class type, Map<String,Object> qo, Map<String,Integer> sort, Map<String,Object> projection, String collection, int skip, int limit)javax.cache.CacheManagergetCacheManager()<T> List<T>getFromCache(Class<? extends T> type, String k)return object by from cache.<T> TgetFromIDCache(Class<? extends T> type, Object id)Map<String,Integer>getSizes()booleanisCached(Class<?> type, String k)booleanisListenerRegistered(CacheListener cl)voidremoveCacheListener(CacheListener cl)voidremoveEntryFromCache(Class cls, Object id)voidremoveEntryFromIdCache(Class cls, Object id)voidresetCache()voidsetAnnotationAndReflectionHelper(AnnotationAndReflectionHelper hlp)voidsetCache(Map<Class<?>,Map<String,CacheEntry>> cache)voidsetCacheManager(javax.cache.CacheManager cacheManager)voidsetDefaultCacheTime(Class type)reset cache time settings to default, if settings were cahnged using setValidCacheTimevoidsetGlobalCacheTimeout(int tm)voidsetHouskeepingIntervalPause(int p)voidsetValidCacheTime(Class type, int time)override the settings given in @Cache annotation with this value this is useful to change cache behaviour during runtime
-
-
-
Method Detail
-
setGlobalCacheTimeout
public void setGlobalCacheTimeout(int tm)
- Specified by:
setGlobalCacheTimeoutin interfaceMorphiumCache
-
setHouskeepingIntervalPause
public void setHouskeepingIntervalPause(int p)
- Specified by:
setHouskeepingIntervalPausein interfaceMorphiumCache
-
setAnnotationAndReflectionHelper
public void setAnnotationAndReflectionHelper(AnnotationAndReflectionHelper hlp)
- Specified by:
setAnnotationAndReflectionHelperin interfaceMorphiumCache
-
addCacheListener
public void addCacheListener(CacheListener cl)
- Specified by:
addCacheListenerin interfaceMorphiumCache
-
isListenerRegistered
public boolean isListenerRegistered(CacheListener cl)
- Specified by:
isListenerRegisteredin interfaceMorphiumCache
-
removeCacheListener
public void removeCacheListener(CacheListener cl)
- Specified by:
removeCacheListenerin interfaceMorphiumCache
-
addToCache
public <T> void addToCache(String k, Class<? extends T> type, List<T> ret)
adds some list of objects to the cache manually... is being used internally, and should be used with care- Specified by:
addToCachein interfaceMorphiumCache- Type Parameters:
T- - Type of record- Parameters:
k- - Key, usually the mongodb query string - should be created by createCacheKeytype- - class typeret- - list of results
-
clearCacheIfNecessary
public void clearCacheIfNecessary(Class cls)
- Specified by:
clearCacheIfNecessaryin interfaceMorphiumCache
-
isCached
public boolean isCached(Class<?> type, String k)
- Specified by:
isCachedin interfaceMorphiumCache
-
getFromCache
public <T> List<T> getFromCache(Class<? extends T> type, String k)
return object by from cache. Cache key usually is the string-representation of the search query.toQueryObject()- Specified by:
getFromCachein interfaceMorphiumCache- Type Parameters:
T- - type param- Parameters:
type- - typek- - cache key- Returns:
- resulting list
-
getCache
public Map<Class<?>,Map<String,CacheEntry>> getCache()
-
setCache
public void setCache(Map<Class<?>,Map<String,CacheEntry>> cache)
-
getFromIDCache
public <T> T getFromIDCache(Class<? extends T> type, Object id)
- Specified by:
getFromIDCachein interfaceMorphiumCache
-
setValidCacheTime
public void setValidCacheTime(Class type, int time)
Description copied from interface:MorphiumCacheoverride the settings given in @Cache annotation with this value this is useful to change cache behaviour during runtime- Specified by:
setValidCacheTimein interfaceMorphiumCache
-
setDefaultCacheTime
public void setDefaultCacheTime(Class type)
Description copied from interface:MorphiumCachereset cache time settings to default, if settings were cahnged using setValidCacheTime- Specified by:
setDefaultCacheTimein interfaceMorphiumCache
-
getCacheKey
public String getCacheKey(Class type, Map<String,Object> qo, Map<String,Integer> sort, Map<String,Object> projection, String collection, int skip, int limit)
- Specified by:
getCacheKeyin interfaceMorphiumCache
-
getCacheKey
public String getCacheKey(Query q)
create unique cache key for queries, also honoring skip & limit and sorting- Specified by:
getCacheKeyin interfaceMorphiumCache- Parameters:
q- the query- Returns:
- the resulting cache key
-
clearCachefor
public void clearCachefor(Class<?> cls)
- Specified by:
clearCacheforin interfaceMorphiumCache
-
getCachedTypes
public Set<Class<?>> getCachedTypes()
- Specified by:
getCachedTypesin interfaceMorphiumCache
-
resetCache
public void resetCache()
- Specified by:
resetCachein interfaceMorphiumCache
-
close
public void close()
- Specified by:
closein interfaceMorphiumCache
-
removeEntryFromIdCache
public void removeEntryFromIdCache(Class cls, Object id)
- Specified by:
removeEntryFromIdCachein interfaceMorphiumCache
-
removeEntryFromCache
public void removeEntryFromCache(Class cls, Object id)
- Specified by:
removeEntryFromCachein interfaceMorphiumCache
-
getSizes
public Map<String,Integer> getSizes()
- Specified by:
getSizesin interfaceMorphiumCache
-
setCacheManager
public void setCacheManager(javax.cache.CacheManager cacheManager)
- Specified by:
setCacheManagerin interfaceMorphiumCache
-
getCacheManager
public javax.cache.CacheManager getCacheManager()
- Specified by:
getCacheManagerin interfaceMorphiumCache
-
-