當前位置: 首頁>>代碼示例>>Java>>正文


Java CacheManager.getCache方法代碼示例

本文整理匯總了Java中org.springframework.cache.CacheManager.getCache方法的典型用法代碼示例。如果您正苦於以下問題:Java CacheManager.getCache方法的具體用法?Java CacheManager.getCache怎麽用?Java CacheManager.getCache使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.cache.CacheManager的用法示例。


在下文中一共展示了CacheManager.getCache方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testDynamicMode

import org.springframework.cache.CacheManager; //導入方法依賴的package包/類
@Test
public void testDynamicMode() {
	CacheManager cm = new GuavaCacheManager();
	Cache cache1 = cm.getCache("c1");
	assertTrue(cache1 instanceof GuavaCache);
	Cache cache1again = cm.getCache("c1");
	assertSame(cache1again, cache1);
	Cache cache2 = cm.getCache("c2");
	assertTrue(cache2 instanceof GuavaCache);
	Cache cache2again = cm.getCache("c2");
	assertSame(cache2again, cache2);
	Cache cache3 = cm.getCache("c3");
	assertTrue(cache3 instanceof GuavaCache);
	Cache cache3again = cm.getCache("c3");
	assertSame(cache3again, cache3);

	cache1.put("key1", "value1");
	assertEquals("value1", cache1.get("key1").get());
	cache1.put("key2", 2);
	assertEquals(2, cache1.get("key2").get());
	cache1.put("key3", null);
	assertNull(cache1.get("key3").get());
	cache1.evict("key3");
	assertNull(cache1.get("key3"));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:26,代碼來源:GuavaCacheManagerTests.java

示例2: addMetrics

import org.springframework.cache.CacheManager; //導入方法依賴的package包/類
private void addMetrics(Collection<Metric<?>> metrics, String cacheName,
		List<CacheManagerBean> cacheManagerBeans) {
	for (CacheManagerBean cacheManagerBean : cacheManagerBeans) {
		CacheManager cacheManager = cacheManagerBean.getCacheManager();
		Cache cache = cacheManager.getCache(cacheName);
		CacheStatistics statistics = getCacheStatistics(cache, cacheManager);
		if (statistics != null) {
			String prefix = cacheName;
			if (cacheManagerBeans.size() > 1) {
				prefix = cacheManagerBean.getBeanName() + "_" + prefix;
			}
			prefix = "cache." + prefix + (prefix.endsWith(".") ? "" : ".");
			metrics.addAll(statistics.toMetrics(prefix));
		}
	}
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:17,代碼來源:CachePublicMetrics.java

示例3: getCache

import org.springframework.cache.CacheManager; //導入方法依賴的package包/類
@Override
public Cache getCache(String name) {
	for (CacheManager cacheManager : this.cacheManagers) {
		Cache cache = cacheManager.getCache(name);
		if (cache != null) {
			return cache;
		}
	}
	return null;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:11,代碼來源:CompositeCacheManager.java

示例4: testDynamicMode

import org.springframework.cache.CacheManager; //導入方法依賴的package包/類
@Test
public void testDynamicMode() {
	CacheManager cm = new ConcurrentMapCacheManager();
	Cache cache1 = cm.getCache("c1");
	assertTrue(cache1 instanceof ConcurrentMapCache);
	Cache cache1again = cm.getCache("c1");
	assertSame(cache1again, cache1);
	Cache cache2 = cm.getCache("c2");
	assertTrue(cache2 instanceof ConcurrentMapCache);
	Cache cache2again = cm.getCache("c2");
	assertSame(cache2again, cache2);
	Cache cache3 = cm.getCache("c3");
	assertTrue(cache3 instanceof ConcurrentMapCache);
	Cache cache3again = cm.getCache("c3");
	assertSame(cache3again, cache3);

	cache1.put("key1", "value1");
	assertEquals("value1", cache1.get("key1").get());
	cache1.put("key2", 2);
	assertEquals(2, cache1.get("key2").get());
	cache1.put("key3", null);
	assertNull(cache1.get("key3").get());
	cache1.put("key3", null);
	assertNull(cache1.get("key3").get());
	cache1.evict("key3");
	assertNull(cache1.get("key3"));

	assertEquals("value1", cache1.putIfAbsent("key1", "value1x").get());
	assertEquals("value1", cache1.get("key1").get());
	assertEquals(2, cache1.putIfAbsent("key2", 2.1).get());
	assertNull(cache1.putIfAbsent("key3", null));
	assertNull(cache1.get("key3").get());
	assertNull(cache1.putIfAbsent("key3", null).get());
	assertNull(cache1.get("key3").get());
	cache1.evict("key3");
	assertNull(cache1.get("key3"));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:38,代碼來源:ConcurrentMapCacheManagerTests.java

示例5: fooGetSimple

import org.springframework.cache.CacheManager; //導入方法依賴的package包/類
private void fooGetSimple(ApplicationContext context, FooService service) {
	CacheManager cacheManager = context.getBean(CacheManager.class);

	Cache cache = cacheManager.getCache("testCache");

	Object key = new Object();
	assertCacheMiss(key, cache);

	Object value = service.getSimple(key);
	assertCacheHit(key, value, cache);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:12,代碼來源:EnableCachingIntegrationTests.java

示例6: testCustomCacheManager

import org.springframework.cache.CacheManager; //導入方法依賴的package包/類
@Test
public void testCustomCacheManager() {
	CacheManager customCm = ctx.getBean("customCacheManager", CacheManager.class);
	Object key = new Object();
	Object r1 = cs.customCacheManager(key);
	assertSame(r1, cs.customCacheManager(key));

	Cache cache = customCm.getCache("testCache");
	assertNotNull(cache.get(key));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:11,代碼來源:AbstractCacheAnnotationTests.java

示例7: getCache

import org.springframework.cache.CacheManager; //導入方法依賴的package包/類
Cache getCache() {
	ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
	ApplicationContext context = RequestContextUtils.findWebApplicationContext(attributes.getRequest());
	CacheManager cacheManager = context.getBean(CacheManager.class);
	Cache cache = cacheManager.getCache("orderLines");
	return cache;
}
 
開發者ID:rajadilipkolli,項目名稱:springsecuredthymeleafapp,代碼行數:8,代碼來源:CachingCart.java

示例8: setCacheManager

import org.springframework.cache.CacheManager; //導入方法依賴的package包/類
@Autowired
public void setCacheManager(CacheManager cacheManager) {
    cache = cacheManager.getCache(Constants.Cache.CONTEST_ONLY);
}
 
開發者ID:zjnu-acm,項目名稱:judge,代碼行數:5,代碼來源:ContestOnlyService.java

示例9: CachingResourceTransformer

import org.springframework.cache.CacheManager; //導入方法依賴的package包/類
public CachingResourceTransformer(CacheManager cacheManager, String cacheName) {
	this(cacheManager.getCache(cacheName));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:4,代碼來源:CachingResourceTransformer.java

示例10: CachingResourceResolver

import org.springframework.cache.CacheManager; //導入方法依賴的package包/類
public CachingResourceResolver(CacheManager cacheManager, String cacheName) {
	this(cacheManager.getCache(cacheName));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:4,代碼來源:CachingResourceResolver.java

示例11: OAuthServiceImpl

import org.springframework.cache.CacheManager; //導入方法依賴的package包/類
@Autowired
public OAuthServiceImpl(CacheManager cacheManager) {
    this.cache = cacheManager.getCache("code-cache");
}
 
開發者ID:xiaomin0322,項目名稱:oauth_demo,代碼行數:5,代碼來源:OAuthServiceImpl.java

示例12: OAuth2Service

import org.springframework.cache.CacheManager; //導入方法依賴的package包/類
@Autowired
public OAuth2Service(CacheManager cacheManager) {
    this.codeCache = cacheManager.getCache(CACHE_CODE);
    this.tokenCache = cacheManager.getCache(CACHE_ACCESSTOKEN);
}
 
開發者ID:microacup,項目名稱:microbbs,代碼行數:6,代碼來源:OAuth2Service.java


注:本文中的org.springframework.cache.CacheManager.getCache方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。