use of cn.taketoday.cache.support.CaffeineCacheManager in project today-infrastructure by TAKETODAY.
the class CaffeineCacheManagerTests method changeCacheLoaderRecreateCache.
@Test
public void changeCacheLoaderRecreateCache() {
CaffeineCacheManager cm = new CaffeineCacheManager("c1");
Cache cache1 = cm.getCache("c1");
@SuppressWarnings("unchecked") CacheLoader<Object, Object> loader = mock(CacheLoader.class);
cm.setCacheLoader(loader);
Cache cache1x = cm.getCache("c1");
assertThat(cache1x != cache1).isTrue();
// Set same instance
cm.setCacheLoader(loader);
Cache cache1xx = cm.getCache("c1");
assertThat(cache1xx).isSameAs(cache1x);
}
use of cn.taketoday.cache.support.CaffeineCacheManager in project today-infrastructure by TAKETODAY.
the class CaffeineCacheManagerTests method setCacheNameNullRestoreDynamicMode.
@Test
public void setCacheNameNullRestoreDynamicMode() {
CaffeineCacheManager cm = new CaffeineCacheManager("c1");
assertThat(cm.getCache("someCache")).isNull();
cm.setCacheNames(null);
assertThat(cm.getCache("someCache")).isNotNull();
}
use of cn.taketoday.cache.support.CaffeineCacheManager in project today-infrastructure by TAKETODAY.
the class CaffeineCacheManagerTests method customCacheRegistration.
@Test
public void customCacheRegistration() {
CaffeineCacheManager cm = new CaffeineCacheManager("c1");
com.github.benmanes.caffeine.cache.Cache<Object, Object> nc = Caffeine.newBuilder().build();
cm.registerCustomCache("c2", nc);
Cache cache1 = cm.getCache("c1");
Cache cache2 = cm.getCache("c2");
assertThat(nc == cache2.getNativeCache()).isTrue();
cm.setCaffeine(Caffeine.newBuilder().maximumSize(10));
assertThat(cm.getCache("c1") != cache1).isTrue();
assertThat(cm.getCache("c2") == cache2).isTrue();
}
use of cn.taketoday.cache.support.CaffeineCacheManager in project today-infrastructure by TAKETODAY.
the class CaffeineCacheManagerTests method changeCacheSpecificationRecreateCache.
@Test
public void changeCacheSpecificationRecreateCache() {
CaffeineCacheManager cm = new CaffeineCacheManager("c1");
Cache cache1 = cm.getCache("c1");
cm.setCacheSpecification("maximumSize=10");
Cache cache1x = cm.getCache("c1");
assertThat(cache1x != cache1).isTrue();
}
use of cn.taketoday.cache.support.CaffeineCacheManager in project today-infrastructure by TAKETODAY.
the class CaffeineCacheManagerTests method cacheLoaderUseLoadingCache.
@Test
public void cacheLoaderUseLoadingCache() {
CaffeineCacheManager cm = new CaffeineCacheManager("c1");
cm.setCacheLoader(key -> {
if ("ping".equals(key)) {
return "pong";
}
throw new IllegalArgumentException("I only know ping");
});
Cache cache1 = cm.getCache("c1");
Cache.ValueWrapper value = cache1.get("ping");
assertThat(value).isNotNull();
assertThat(value.get()).isEqualTo("pong");
assertThatIllegalArgumentException().isThrownBy(() -> assertThat(cache1.get("foo")).isNull()).withMessageContaining("I only know ping");
}
Aggregations