CacheManager优化
This commit is contained in:
@@ -40,11 +40,11 @@ public class CacheInstance implements Service {
|
||||
return "haha";
|
||||
}
|
||||
|
||||
public void updateName() {
|
||||
cacheManager.bothSet("name", String.class, "gege", Duration.ofMillis(600), Duration.ofMillis(600));
|
||||
public void updateName(String val) {
|
||||
cacheManager.bothSet("name_2", String.class, val, Duration.ofSeconds(31), Duration.ofSeconds(60));
|
||||
}
|
||||
|
||||
@Cached(key = "name", localExpire = "30", remoteExpire = "60")
|
||||
@Cached(key = "name_2", localExpire = "31", remoteExpire = "60")
|
||||
public String getName2() throws RedkaleException {
|
||||
return "haha";
|
||||
}
|
||||
@@ -80,6 +80,10 @@ public class CacheInstance implements Service {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
public CacheManager getCacheManager() {
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
public static class ParamBean {
|
||||
|
||||
private String name;
|
||||
|
||||
@@ -60,6 +60,7 @@ public class CacheInstanceTest {
|
||||
public void run1() throws Exception {
|
||||
Class<CacheInstance> serviceClass = CacheInstance.class;
|
||||
CacheAsmMethodBoost boost = new CacheAsmMethodBoost(false, serviceClass);
|
||||
CacheAsmMethodBoost boost2 = new CacheAsmMethodBoost(false, serviceClass);
|
||||
SncpRpcGroups grous = new SncpRpcGroups();
|
||||
AsyncGroup iGroup = AsyncGroup.create("", Utility.newScheduledExecutor(1), 0, 0);
|
||||
SncpClient client = new SncpClient(
|
||||
@@ -68,12 +69,24 @@ public class CacheInstanceTest {
|
||||
null, "", serviceClass, boost, resourceFactory, grous, client, null, null, null);
|
||||
resourceFactory.inject(instance);
|
||||
CacheInstance instance2 = Sncp.createLocalService(
|
||||
null, "", serviceClass, boost, resourceFactory2, grous, client, null, null, null);
|
||||
null, "", serviceClass, boost2, resourceFactory2, grous, client, null, null, null);
|
||||
resourceFactory2.inject(instance2);
|
||||
System.out.println(instance.getName2());
|
||||
System.out.println(instance.getClass());
|
||||
Assertions.assertEquals("haha", instance.getName2());
|
||||
Assertions.assertEquals("haha", instance2.getName2());
|
||||
instance.updateName();
|
||||
System.out.println("准备设置 updateName");
|
||||
System.out.println("instance1.manager = " + instance.getCacheManager());
|
||||
System.out.println("instance2.manager = " + instance2.getCacheManager());
|
||||
manager.updateBroadcastable(false);
|
||||
instance.updateName("gege");
|
||||
Assertions.assertEquals("gege", instance.getName2());
|
||||
Assertions.assertEquals("haha", instance2.getName2());
|
||||
manager.updateBroadcastable(true);
|
||||
System.out.println("准备设置 updateName");
|
||||
instance.updateName("gege");
|
||||
System.out.println("设置结束 updateName");
|
||||
Utility.sleep(10);
|
||||
Assertions.assertEquals("gege", instance.getName2());
|
||||
Assertions.assertEquals("gege", instance2.getName2());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user