当前位置: 首页>>代码示例>>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;未经允许,请勿转载。