【发布时间】:2013-11-11 23:40:26
【问题描述】:
能否请您给我实现 SelfPouplatingEhcache 的步骤。
问候, 拉朱
【问题讨论】:
标签: ehcache
能否请您给我实现 SelfPouplatingEhcache 的步骤。
问候, 拉朱
【问题讨论】:
标签: ehcache
SelfPopulatingCache 充当EhCache 另一个实例的包装器(或装饰器)。当您向SelfPopulatingCache 询问缓存值时,该值不在底层缓存中,SelfPopulatingCache 将为您创建该值。它使用您还提供的CacheEntryFactory 来执行此操作。
所以要创建SelfPopulatingCache,您需要:
EhCache 的实例,您从 ChacheManager 获取
CacheEntryFactory 的实例,您自己编写。将它们都传递给SelfPopulatingCache 的构造函数,然后就可以了。
【讨论】:
SelfPopulatingCache cacheStatus = new SelfPopulatingCache(ehcache, new CacheEntryFactory() {
@Override
public Object createEntry(Object key) throws Exception {
if (key.toString().equals(FLAG1)) {
return true;
} else if (key.toString().equals(FLAG2)) {
return false;
}
return null;
}
});
【讨论】: