CacheManager

This commit is contained in:
redkale
2023-12-11 15:18:51 +08:00
parent bd088ab9ec
commit 71a7e7e7f6
4 changed files with 590 additions and 312 deletions

View File

@@ -7,7 +7,7 @@ import java.time.Duration;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.redkale.caching.CacheConfig;
import org.redkale.caching.CacheManager;
import org.redkale.caching.CacheManagerService;
import org.redkale.convert.json.JsonConvert;
import org.redkale.source.CacheMemorySource;
import org.redkale.util.Utility;
@@ -25,7 +25,10 @@ public class CachingTest {
@Test
public void run() throws Exception {
CacheManager cache = CacheManager.create(new CacheConfig(), new CacheMemorySource("remote"));
CacheMemorySource remoteSource = new CacheMemorySource("remote");
remoteSource.init(null);
CacheManagerService cache = CacheManagerService.create(new CacheConfig(), remoteSource);
cache.init(null);
Duration expire = Duration.ofMillis(490);
cache.localSetString("user", "name:haha", "myha", expire);
Assertions.assertEquals(cache.localGetString("user", "name:haha"), "myha");
@@ -41,6 +44,7 @@ public class CachingTest {
Assertions.assertEquals(cache.localGet("user", bean.getName(), CachingBean.class).toString(), json);
bean.setRemark(bean.getRemark() + "-新备注");
Assertions.assertEquals(cache.localGet("user", bean.getName(), CachingBean.class).toString(), json);
cache.destroy(null);
}
public static class CachingBean {