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