Ehcache(2.9.x) - API Developer Guide, Cache Extensions
About Cache Extensions
Cache extensions are a general-purpose mechanism to allow generic extensions to a cache. Cache extensions are tied into the cache lifecycle. For that reason, this interface has the lifecycle methods.
Cache extensions are created using the CacheExtensionFactory, which has a createCacheCacheExtension() method that takes as a parameter a Cache and properties. It can thus call back into any public method on Cache, including, of course, the load methods. Cache extensions are suitable for timing services, where you want to create a timer to perform cache operations. (Another way of adding Cache behavior is to decorate a cache. For an example of, Blocking and Self Populating Caches.)
Because a CacheExtension holds a reference to a Cache, the CacheExtension can do things such as registering a CacheEventListener or even a CacheManagerEventListener, all from within a CacheExtension, creating more opportunities for customization.
Declarative Configuration
Cache extensions are configured per cache. Each cache can have zero or more.
You configure a cache extension by adding a cacheExceptionHandlerFactory element as shown in the following example:
<cache ...>
<cacheExtensionFactory
class="com.example.FileWatchingCacheRefresherExtensionFactory"
properties="refreshIntervalMillis=18000, loaderTimeout=3000, flushPeriod=whatever, ..."/>
</cache>
Implementing a Cache Extension Factory and Cache Extension
A CacheExtensionFactory is an abstract factory for creating cache extension. Implementers should provide their own concrete factory, extending this abstract factory. It can then be configured in ehcache.xml. The factory class needs to be a concrete subclass of the abstract factory class CacheExtensionFactory, which is reproduced below:
/**
* An abstract factory for creating <code>CacheExtension</code>s. Implementers should provide their own
* concrete factory extending this factory. It can then be configured in ehcache.xml.
*
* @author <a href="mailto:gluck@gregluck.com">Greg Luck</a>
* @version $Id: CacheExtensionFactory.java 5594 2012-05-07 16:04:31Z cdennis $
*/
public abstract class CacheExtensionFactory { /**
* @param cache the cache this extension should hold a reference to, and to whose lifecycle it should be bound.
* @param properties implementation specific properties configured as delimiter separated name value pairs in ehcache.xml
*/
public abstract CacheExtension createCacheExtension(Ehcache cache, Properties properties); }
The factory creates a concrete implementation of the CacheExtension interface, which is reproduced below:
/**
* This is a general purpose mechanism to allow generic extensions to a Cache.
* <p/>
* CacheExtensions are tied into the Cache lifecycle. For that reason this interface has the
* lifecycle methods.
* <p/>
* CacheExtensions are created using the CacheExtensionFactory which has a
* <code>createCacheCacheExtension()</code> method which takes as a parameter a Cache and
* properties. It can thus call back into any public method on Cache, including, of course,
* the load methods.
* <p/>
* CacheExtensions are suitable for timing services, where you want to create a timer to
* perform cache operations. The other way of adding Cache behaviour is to decorate a cache.
* See {@link net.sf.ehcache.constructs.blocking.BlockingCache} for an example of how to do
* this.
* <p/>
* Because a CacheExtension holds a reference to a Cache, the CacheExtension can do things
* such as registering a CacheEventListener or even a CacheManagerEventListener, all from
* within a CacheExtension, creating more opportunities for customisation.
*
* @author <a href="mailto:gluck@gregluck.com">Greg Luck</a>
* @version $Id: CacheExtension.java 5594 2012-05-07 16:04:31Z cdennis $
*/
public interface CacheExtension { /**
* Notifies providers to initialise themselves.
* <p/>
* This method is called during the Cache's initialise method after it has changed it's
* status to alive. Cache operations are legal in this method.
*
* @throws CacheException
*/
void init(); /**
* Providers may be doing all sorts of exotic things and need to be able to clean up on
* dispose.
* <p/>
* Cache operations are illegal when this method is called. The cache itself is partly
* disposed when this method is called.
*
* @throws CacheException
*/
void dispose() throws CacheException; /**
* Creates a clone of this extension. This method will only be called by ehcache before a
* cache is initialized.
* <p/>
* Implementations should throw CloneNotSupportedException if they do not support clone
* but that will stop them from being used with defaultCache.
*
* @param cache the cache extended
* @return a clone
* @throws CloneNotSupportedException if the extension could not be cloned.
*/
public CacheExtension clone(Ehcache cache) throws CloneNotSupportedException; /**
* @return the status of the extension
*/
public Status getStatus();
}
Programmatic Configuration
Cache extensions can also be programmatically added to a Cache as shown below:
TestCacheExtension testCacheExtension = new TestCacheExtension(cache, ...);
testCacheExtension.init();
cache.registerCacheExtension(testCacheExtension);
Ehcache(2.9.x) - API Developer Guide, Cache Extensions的更多相关文章
- Ehcache(2.9.x) - API Developer Guide, Cache Loaders
About Cache Loaders A CacheLoader is an interface that specifies load() and loadAll() methods with a ...
- Ehcache(2.9.x) - API Developer Guide, Cache Decorators
About Cache Decorators Ehcache uses the Ehcache interface, of which Cache is an implementation. It i ...
- Ehcache(2.9.x) - API Developer Guide, Cache Eviction Algorithms
About Cache Eviction Algorithms A cache eviction algorithm is a way of deciding which element to evi ...
- Ehcache(2.9.x) - API Developer Guide, Cache Usage Patterns
There are several common access patterns when using a cache. Ehcache supports the following patterns ...
- Ehcache(2.9.x) - API Developer Guide, Cache Manager Event Listeners
About CacheManager Event Listeners CacheManager event listeners allow implementers to register callb ...
- Ehcache(2.9.x) - API Developer Guide, Cache Event Listeners
About Cache Event Listeners Cache listeners allow implementers to register callback methods that wil ...
- Ehcache(2.9.x) - API Developer Guide, Cache Exception Handlers
About Exception Handlers By default, most cache operations will propagate a runtime CacheException o ...
- Ehcache(2.9.x) - API Developer Guide, Write-Through and Write-Behind Caches
About Write-Through and Write-Behind Caches Write-through caching is a caching pattern where writes ...
- Ehcache(2.9.x) - API Developer Guide, Searching a Cache
About Searching The Search API allows you to execute arbitrarily complex queries against caches. The ...
随机推荐
- HDU 1394 Minimum Inversion Number (树状数组求逆序对)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1394 题目让你求一个数组,这个数组可以不断把最前面的元素移到最后,让你求其中某个数组中的逆序对最小是多 ...
- jq倒计时
var referTime = 5; setInterval("refer('#show')", 1000); function refer(obj){ if(referTime ...
- 几道 SQL 语句面试题
--S (sno,sname)学生关系,sno为学号 sname为姓名 --C(cno,cname,Cteacher)课程关系 cno为课程号,cname为课程名,cteacher 为任课教师 --S ...
- 来自JavaScript Garden摘取
1.数字类型不能用作对象,因为javascript解析器会将点号(.)解析成浮点型(as a floating point literal),比如:2.toString();会导致语法从错误,解决方法 ...
- Gym 100637F F. The Pool for Lucky Ones 暴力
F. The Pool for Lucky Ones Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/10 ...
- Android Mms 接收信息流程
信息的接收工作是由底层来完成的,当有一个 新的信息时底层完成接收后会以Intent的方式来通知上层应用,信息的相关内容也包含在Intent当中,Android所支持的信息Intent都定 义在andr ...
- iOS开发——UI篇OC篇&UITableView简单封装
UITableView简单封装 UITableView时iOS开发中使用最多也是最重的一个UI空间,其实在App Store里面的%80以上的应用都用到了这个控件,所以就给大家介绍一下,前面的文章中也 ...
- qwt总结1
废话不想太多,说下自己的使用总结. 一般来说,对于一个图表. 可能的话,应该有一个坐标轴,QWT中,是用QwtPlot这个类 来描述一个图的坐标系图(只表示坐标系的背景,没有描点).坐标(刻度)的设置 ...
- debian的备份与还原
不管是windows还是linux 备份都很重要 因为配好一个系统是要花很多时间的 出了问题的话 有备份直接还原就可以了 windows下有ghost 那么linux下呢?Linux可以在系统正在运行 ...
- javascript获取鼠标位置
首先不同浏览器中event位置属性的分析: 1. IE的event.x,event.y是以事件触发元素的父元素外界为参考点(不包括滚动距离) 2. Firefox的event.pageX,event. ...