use of cn.taketoday.cache.support.CaffeineCache in project today-infrastructure by TAKETODAY.
the class CaffeineCacheTests method setUp.
@BeforeEach
void setUp() {
nativeCache = Caffeine.newBuilder().build();
cache = new CaffeineCache(CACHE_NAME, nativeCache);
com.github.benmanes.caffeine.cache.Cache<Object, Object> nativeCacheNoNull = Caffeine.newBuilder().build();
cacheNoNull = new CaffeineCache(CACHE_NAME_NO_NULL, nativeCacheNoNull, false);
}
use of cn.taketoday.cache.support.CaffeineCache in project today-framework by TAKETODAY.
the class CaffeineCacheManagerTests method testStaticMode.
@Test
public void testStaticMode() {
CaffeineCacheManager cm = new CaffeineCacheManager("c1", "c2");
Cache cache1 = cm.getCache("c1");
boolean condition3 = cache1 instanceof CaffeineCache;
assertThat(condition3).isTrue();
Cache cache1again = cm.getCache("c1");
assertThat(cache1).isSameAs(cache1again);
Cache cache2 = cm.getCache("c2");
boolean condition2 = cache2 instanceof CaffeineCache;
assertThat(condition2).isTrue();
Cache cache2again = cm.getCache("c2");
assertThat(cache2).isSameAs(cache2again);
Cache cache3 = cm.getCache("c3");
assertThat(cache3).isNull();
cache1.put("key1", "value1");
assertThat(cache1.get("key1").get()).isEqualTo("value1");
cache1.put("key2", 2);
assertThat(cache1.get("key2").get()).isEqualTo(2);
cache1.put("key3", null);
assertThat(cache1.get("key3").get()).isNull();
cache1.evict("key3");
assertThat(cache1.get("key3")).isNull();
cm.setAllowNullValues(false);
Cache cache1x = cm.getCache("c1");
boolean condition1 = cache1x instanceof CaffeineCache;
assertThat(condition1).isTrue();
assertThat(cache1x != cache1).isTrue();
Cache cache2x = cm.getCache("c2");
boolean condition = cache2x instanceof CaffeineCache;
assertThat(condition).isTrue();
assertThat(cache2x != cache2).isTrue();
Cache cache3x = cm.getCache("c3");
assertThat(cache3x).isNull();
cache1x.put("key1", "value1");
assertThat(cache1x.get("key1").get()).isEqualTo("value1");
cache1x.put("key2", 2);
assertThat(cache1x.get("key2").get()).isEqualTo(2);
cm.setAllowNullValues(true);
Cache cache1y = cm.getCache("c1");
cache1y.put("key3", null);
assertThat(cache1y.get("key3").get()).isNull();
cache1y.evict("key3");
assertThat(cache1y.get("key3")).isNull();
}
use of cn.taketoday.cache.support.CaffeineCache in project today-framework by TAKETODAY.
the class CaffeineCacheTests method testLoadingCacheGetWithType.
@Test
void testLoadingCacheGetWithType() {
String value = "value";
CaffeineCache loadingCache = new CaffeineCache(CACHE_NAME, Caffeine.newBuilder().build(key -> value));
String valueWrapper = loadingCache.get(new Object(), String.class);
assertThat(valueWrapper).isNotNull();
assertThat(valueWrapper).isEqualTo(value);
}
use of cn.taketoday.cache.support.CaffeineCache in project today-framework by TAKETODAY.
the class CaffeineCacheTests method testLoadingCacheGet.
@Test
void testLoadingCacheGet() {
Object value = new Object();
CaffeineCache loadingCache = new CaffeineCache(CACHE_NAME, Caffeine.newBuilder().build(key -> value));
ValueWrapper valueWrapper = loadingCache.get(new Object());
assertThat(valueWrapper).isNotNull();
assertThat(valueWrapper.get()).isEqualTo(value);
}
use of cn.taketoday.cache.support.CaffeineCache in project today-framework by TAKETODAY.
the class CaffeineCacheTests method setUp.
@BeforeEach
void setUp() {
nativeCache = Caffeine.newBuilder().build();
cache = new CaffeineCache(CACHE_NAME, nativeCache);
com.github.benmanes.caffeine.cache.Cache<Object, Object> nativeCacheNoNull = Caffeine.newBuilder().build();
cacheNoNull = new CaffeineCache(CACHE_NAME_NO_NULL, nativeCacheNoNull, false);
}
Aggregations