本文整理匯總了Java中net.sf.ehcache.CacheManager.newInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java CacheManager.newInstance方法的具體用法?Java CacheManager.newInstance怎麽用?Java CacheManager.newInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.sf.ehcache.CacheManager
的用法示例。
在下文中一共展示了CacheManager.newInstance方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testEhcache
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
@Test
public void testEhcache() {
// Creating a CacheManager based on a specified configuration file.
CacheManager manager = CacheManager.newInstance("src/main/resources/ehcache.xml");
// obtains a Cache called sampleCache1, which has been preconfigured in the configuration file
Cache cache = manager.getCache("sampleCache1");
// puts an element into a cache
Element element = new Element("key1", "哈哈");
cache.put(element);
//The following gets a NonSerializable value from an element with a key of key1.
Object value = element.getObjectValue();
System.out.println(value.toString());
manager.shutdown();
}
示例2: cacheExposesMetrics
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
@Test
void cacheExposesMetrics() {
CacheManager cacheManager = CacheManager.newInstance();
cacheManager.addCache("a");
Cache c = cacheManager.getCache("a");
MeterRegistry registry = new SimpleMeterRegistry();
EhCache2Metrics.monitor(registry, c, "ehcache", emptyList());
c.put(new Element("k", "v", 1));
registry.mustFind("ehcache.size").tags("name", "a").gauge();
}
示例3: setUp
import net.sf.ehcache.CacheManager; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
registry = RegistryService.getMetricRegistry();
cacheManager = CacheManager.newInstance();
cache = cacheManager.addCacheIfAbsent(cacheName);
presetElements = IntStream.range(0, 1000).boxed()
.collect(Collectors.toMap(i -> UUID.randomUUID().toString(), i -> i));
presetElementKeys = new ArrayList<>(presetElements.keySet());
}