Package org.javalite.activejdbc.cache
Class CacheManager
- java.lang.Object
-
- org.javalite.activejdbc.cache.CacheManager
-
- Direct Known Subclasses:
EHCache3Manager,EHCacheManager,NopeCacheManager,RedisCacheManager
public abstract class CacheManager extends Object
Abstract method to be sub-classed by various caching technologies.- Author:
- Igor Polevoy
-
-
Constructor Summary
Constructors Constructor Description CacheManager()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidaddCache(String group, String key, Object cache)Adds item to cache.voidaddCacheEventListener(CacheEventListener listener)abstract voiddoFlush(CacheEvent event)voidflush(CacheEvent event)Flashes cache.voidflush(CacheEvent event, boolean propagate)Flashes cache.abstract ObjectgetCache(String group, String key)Returns a cached item.abstract ObjectgetImplementation()Returns underlying instance of implementation for specific configuration.StringgetKey(String tableName, String query, Object[] params)Generates a cache key.voidpurgeTableCache(String tableName)UsepurgeTableCache(MetaModel)whenever you can.voidpurgeTableCache(MetaModel metaModel)This method purges (removes) all caches associated with a table, if caching is enabled and a corresponding model is marked cached.voidremoveAllCacheEventListeners()voidremoveCacheEventListener(CacheEventListener listener)
-
-
-
Method Detail
-
getCache
public abstract Object getCache(String group, String key)
Returns a cached item. Can return null if not found.- Parameters:
group- group of caches - this is a name of a table for which query results are cachedkey- key of the item.- Returns:
- a cached item. Can return null if not found.
-
addCache
public abstract void addCache(String group, String key, Object cache)
Adds item to cache.- Parameters:
group- group name of cache.key- key of the item.cache- cache item to add to cache.
-
doFlush
public abstract void doFlush(CacheEvent event)
-
flush
public final void flush(CacheEvent event, boolean propagate)
Flashes cache.- Parameters:
propagate- true to propagate event to listeners, false to not propagateevent- type of caches to flush.
-
flush
public final void flush(CacheEvent event)
Flashes cache.- Parameters:
event- type of caches to flush.
-
addCacheEventListener
public final void addCacheEventListener(CacheEventListener listener)
-
removeCacheEventListener
public final void removeCacheEventListener(CacheEventListener listener)
-
removeAllCacheEventListeners
public final void removeAllCacheEventListeners()
-
purgeTableCache
public void purgeTableCache(MetaModel metaModel)
This method purges (removes) all caches associated with a table, if caching is enabled and a corresponding model is marked cached.- Parameters:
metaModel- meta-model whose caches are to purge.
-
purgeTableCache
public void purgeTableCache(String tableName)
UsepurgeTableCache(MetaModel)whenever you can.- Parameters:
tableName- name of table whose caches to purge.
-
getKey
public String getKey(String tableName, String query, Object[] params)
Generates a cache key. Subclasses may override this implementation.- Parameters:
tableName- name of a tablequery- queryparams- query parameters.- Returns:
- generated key for tied to these parameters.
-
getImplementation
public abstract Object getImplementation()
Returns underlying instance of implementation for specific configuration.- Returns:
- actual underlying implementation of cache. The same as configured in
activejdbc.propertiesfile. For instance:redis.clients.jedis.JedisPool.
-
-