本文整理汇总了Java中com.github.benmanes.caffeine.cache.CacheLoader类的典型用法代码示例。如果您正苦于以下问题:Java CacheLoader类的具体用法?Java CacheLoader怎么用?Java CacheLoader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CacheLoader类属于com.github.benmanes.caffeine.cache包,在下文中一共展示了CacheLoader类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadingCache
import com.github.benmanes.caffeine.cache.CacheLoader; //导入依赖的package包/类
@Test
public void loadingCache() throws Exception {
Config conf = ConfigFactory.empty()
.withValue("caffeine.cache", ConfigValueFactory.fromAnyRef(""))
.withValue("caffeine.session", ConfigValueFactory.fromAnyRef(""));
new MockUnit(Env.class)
.run(unit -> {
Injector injector = Guice.createInjector(binder -> {
new CaffeineCache<String, Object>(){}.doWith((n, b) ->{
return b.build(new CacheLoader<String, Object>() {
@Override
public Object load(final String key) throws Exception {
return null;
}
});
}).configure(unit.get(Env.class), conf, binder);
});
injector.getInstance(RequireCache.class);
injector.getInstance(RequireLoadingCache.class);
injector.getInstance(CaffeineSessionStore.class);
});
}
示例2: ayncLoadingCache
import com.github.benmanes.caffeine.cache.CacheLoader; //导入依赖的package包/类
@Test
public void ayncLoadingCache() throws Exception {
Config conf = ConfigFactory.empty()
.withValue("caffeine.cache", ConfigValueFactory.fromAnyRef(""))
.withValue("caffeine.session", ConfigValueFactory.fromAnyRef(""));
new MockUnit(Env.class)
.run(unit -> {
Injector injector = Guice.createInjector(binder -> {
new CaffeineCache<String, Object>(){}.doWithAsync((n, b) ->{
return b.buildAsync(new CacheLoader<String, Object>() {
@Override
public Object load(final String key) throws Exception {
return null;
}
});
}).configure(unit.get(Env.class), conf, binder);
});
injector.getInstance(RequireAsyncLoadingCache.class);
});
}
示例3: CaffeineCacheConfiguration
import com.github.benmanes.caffeine.cache.CacheLoader; //导入依赖的package包/类
CaffeineCacheConfiguration(CacheProperties cacheProperties,
CacheManagerCustomizers customizers,
ObjectProvider<Caffeine<Object, Object>> caffeineProvider,
ObjectProvider<CaffeineSpec> caffeineSpecProvider,
ObjectProvider<CacheLoader<Object, Object>> cacheLoaderProvider) {
this.cacheProperties = cacheProperties;
this.customizers = customizers;
this.caffeine = caffeineProvider.getIfAvailable();
this.caffeineSpec = caffeineSpecProvider.getIfAvailable();
this.cacheLoader = cacheLoaderProvider.getIfAvailable();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:CaffeineCacheConfiguration.java
示例4: loadingCacheExposesMetricsForLoadsAndExceptions
import com.github.benmanes.caffeine.cache.CacheLoader; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void loadingCacheExposesMetricsForLoadsAndExceptions() throws Exception {
CacheLoader<String, String> loader = mock(CacheLoader.class);
when(loader.load(anyString()))
.thenReturn("First User")
.thenThrow(new RuntimeException("Seconds time fails"))
.thenReturn("Third User");
LoadingCache<String, String> cache = Caffeine.newBuilder().recordStats().build(loader);
CollectorRegistry registry = new CollectorRegistry();
CacheMetricsCollector collector = new CacheMetricsCollector().register(registry);
collector.addCache("loadingusers", cache);
cache.get("user1");
cache.get("user1");
try {
cache.get("user2");
} catch (Exception e) {
// ignoring.
}
cache.get("user3");
assertMetric(registry, "caffeine_cache_hit_total", "loadingusers", 1.0);
assertMetric(registry, "caffeine_cache_miss_total", "loadingusers", 3.0);
assertMetric(registry, "caffeine_cache_load_failure_total", "loadingusers", 1.0);
assertMetric(registry, "caffeine_cache_loads_total", "loadingusers", 3.0);
assertMetric(registry, "caffeine_cache_load_duration_seconds_count", "loadingusers", 3.0);
assertMetricGreatThan(registry, "caffeine_cache_load_duration_seconds_sum", "loadingusers", 0.0);
}
示例5: createLoadingCache
import com.github.benmanes.caffeine.cache.CacheLoader; //导入依赖的package包/类
@Override
public <K, V> LoadingBenchmarkCache<K, V> createLoadingCache(
final Class<K> _keyType, final Class<V> _valueType,
final int _maxElements, final BenchmarkCacheSource<K, V> _source) {
MyLoadingBenchmarkCache c = new MyLoadingBenchmarkCache();
c.size = _maxElements;
c.cache = createCache(_maxElements).build(new CacheLoader<K, V>() {
@Override
public V load(final K key) throws Exception {
return _source.load(key);
}
});
return c;
}
示例6: before
import com.github.benmanes.caffeine.cache.CacheLoader; //导入依赖的package包/类
@Before
public void before() throws Exception {
CacheLoader<Integer, Integer> cl = new CacheLoader<Integer, Integer>() {
public Integer load(Integer key) throws Exception {
return key + 1;
}
};
cache = Caffeine.newBuilder().build(cl);
camelctx = new WildFlyCamelContext();
Context jndi = camelctx.getNamingContext();
jndi.rebind("cache", cache);
}