本文整理匯總了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;
}