本文整理汇总了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"));
}
示例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;
}
示例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"));
}
示例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);
}
示例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));
}
示例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;
}
示例8: setCacheManager
import org.springframework.cache.CacheManager; //导入方法依赖的package包/类
@Autowired
public void setCacheManager(CacheManager cacheManager) {
cache = cacheManager.getCache(Constants.Cache.CONTEST_ONLY);
}
示例9: CachingResourceTransformer
import org.springframework.cache.CacheManager; //导入方法依赖的package包/类
public CachingResourceTransformer(CacheManager cacheManager, String cacheName) {
this(cacheManager.getCache(cacheName));
}
示例10: CachingResourceResolver
import org.springframework.cache.CacheManager; //导入方法依赖的package包/类
public CachingResourceResolver(CacheManager cacheManager, String cacheName) {
this(cacheManager.getCache(cacheName));
}
示例11: OAuthServiceImpl
import org.springframework.cache.CacheManager; //导入方法依赖的package包/类
@Autowired
public OAuthServiceImpl(CacheManager cacheManager) {
this.cache = cacheManager.getCache("code-cache");
}
示例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);
}