use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.
the class AbstractCacheAnnotationTests method testMethodName.
protected void testMethodName(CacheableService<?> service, String keyName) {
Object key = new Object();
Object r1 = service.name(key);
assertThat(service.name(key)).isSameAs(r1);
Cache cache = this.cm.getCache("testCache");
// assert the method name is used
assertThat(cache.get(keyName)).isNotNull();
}
use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.
the class AbstractCacheAnnotationTests method testMultiConditionalCacheAndEvict.
protected void testMultiConditionalCacheAndEvict(CacheableService<?> service) {
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
Object key = 1;
secondary.put(key, key);
assertThat(primary.get(key)).isNull();
assertThat(secondary.get(key).get()).isSameAs(key);
Object r1 = service.multiConditionalCacheAndEvict(key);
Object r3 = service.multiConditionalCacheAndEvict(key);
assertThat(!r1.equals(r3)).isTrue();
assertThat(primary.get(key)).isNull();
Object key2 = 3;
Object r2 = service.multiConditionalCacheAndEvict(key2);
assertThat(service.multiConditionalCacheAndEvict(key2)).isSameAs(r2);
// assert the method name is used
assertThat(primary.get(key2).get()).isSameAs(r2);
assertThat(secondary.get(key2)).isNull();
}
use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.
the class AbstractCacheAnnotationTests method testUnlessExpression.
protected void testUnlessExpression(CacheableService<?> service) {
Cache cache = this.cm.getCache("testCache");
cache.clear();
service.unless(10);
service.unless(11);
assertThat(cache.get(10).get()).isEqualTo(10L);
assertThat(cache.get(11)).isNull();
}
use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.
the class AbstractJCacheAnnotationTests method putWithExceptionVetoPut.
@Test
public void putWithExceptionVetoPut() {
Cache cache = getCache(DEFAULT_CACHE);
Object key = createKey(this.keyItem);
Object value = new Object();
assertThat(cache.get(key)).isNull();
assertThatNullPointerException().isThrownBy(() -> service.putWithException(this.keyItem, value, false));
assertThat(cache.get(key)).isNull();
}
use of cn.taketoday.cache.Cache in project today-infrastructure by TAKETODAY.
the class AbstractJCacheAnnotationTests method earlyPutWithException.
@Test
public void earlyPutWithException() {
Cache cache = getCache(DEFAULT_CACHE);
Object key = createKey(this.keyItem);
Object value = new Object();
assertThat(cache.get(key)).isNull();
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> service.earlyPutWithException(this.keyItem, value, true));
Cache.ValueWrapper result = cache.get(key);
assertThat(result).isNotNull();
assertThat(result.get()).isEqualTo(value);
}
Aggregations