本文整理汇总了Java中org.ehcache.CacheManagerBuilder类的典型用法代码示例。如果您正苦于以下问题:Java CacheManagerBuilder类的具体用法?Java CacheManagerBuilder怎么用?Java CacheManagerBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CacheManagerBuilder类属于org.ehcache包,在下文中一共展示了CacheManagerBuilder类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: EHCache3Manager
import org.ehcache.CacheManagerBuilder; //导入依赖的package包/类
public EHCache3Manager() throws ClassNotFoundException, SAXException, InstantiationException, IOException, IllegalAccessException {
URL url = getClass().getResource("/activejdbc-ehcache.xml");
if(url == null){
throw new InitException("You are using " + getClass().getName() + " but failed to provide a EHCache configuration file on classpath: activejdbc-ehcache.xml");
}
XmlConfiguration xmlConfiguration = new XmlConfiguration(url);
cacheTemplate = xmlConfiguration.newCacheConfigurationBuilderFromTemplate("activejdbc", String.class, Object.class);
if(cacheTemplate == null){
throw new InitException("Please, provide a <cache-template name=\"activejdbc\"> element in activejdbc-ehcache.xml file");
}
cacheManager = CacheManagerBuilder.newCacheManager(xmlConfiguration);
cacheManager.init();
}
示例2: main
import org.ehcache.CacheManagerBuilder; //导入依赖的package包/类
public static void main(String[] args){
CacheManager cacheManager = CacheManagerBuilder.newCacheManagerBuilder()
.withCache("preConfigured",
CacheConfigurationBuilder.newCacheConfigurationBuilder().buildConfig(Long.class, String.class))
.build(true);
Cache<Long, String> preConfigured
= cacheManager.getCache("preConfigured", Long.class, String.class);
Cache<Long, TestData> myCache = cacheManager.createCache("myCache",
CacheConfigurationBuilder.newCacheConfigurationBuilder().buildConfig(Long.class, TestData.class));
Cache<Long, TestData2> myCache2 = cacheManager.createCache("myCache2",
CacheConfigurationBuilder.newCacheConfigurationBuilder().buildConfig(Long.class, TestData2.class));
TestData data=new TestData();
myCache.put(1L, data);
myCache.put(1L, data);
myCache.put(1L,new TestData());
myCache.put(1L, data);
myCache2.put(2l,data.testData2);
data.a=30;
data.testData2.a=50;
TestData value = myCache.get(1L);
System.out.println(value);
cacheManager.close();
}
示例3: getCacheManager
import org.ehcache.CacheManagerBuilder; //导入依赖的package包/类
private synchronized PersistentCacheManager getCacheManager()
{
if (this.manager == null)
{
this.manager = CacheManagerBuilder.newCacheManagerBuilder().with(new CacheManagerPersistenceConfiguration(new File(this.cacheFileLocation, this.cacheName))).build(true);
}
return this.manager;
}