CachedAction
This commit is contained in:
@@ -182,6 +182,15 @@ public class CachedAction {
|
||||
return key;
|
||||
}
|
||||
|
||||
public int getLocalLimit() {
|
||||
return localLimit;
|
||||
}
|
||||
|
||||
public void setLocalLimit(int localLimit) {
|
||||
this.localLimit = localLimit;
|
||||
((CachedManagerService) manager).getLocalSource().updateLimit(getName(), localLimit);
|
||||
}
|
||||
|
||||
public Duration getLocalExpire() {
|
||||
return localExpire;
|
||||
}
|
||||
|
||||
@@ -136,6 +136,7 @@ public class CachedLocalSource implements Service {
|
||||
}
|
||||
int old = map.limit;
|
||||
map.limit = limit;
|
||||
map.checkLimit();
|
||||
return old;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,10 +75,10 @@ public class CachedManagerService implements CachedManager, CachedActionFunc, Se
|
||||
protected final CachedLocalSource localSource = new CachedLocalSource();
|
||||
|
||||
// 缓存无效时使用的同步锁
|
||||
private final ConcurrentHashMap<String, CachedValue> syncLockMap = new ConcurrentHashMap<>();
|
||||
protected final ConcurrentHashMap<String, CachedValue> syncLockMap = new ConcurrentHashMap<>();
|
||||
|
||||
// 缓存无效时使用的异步锁
|
||||
private final ConcurrentHashMap<String, CachedAsyncLock> asyncLockMap = new ConcurrentHashMap<>();
|
||||
protected final ConcurrentHashMap<String, CachedAsyncLock> asyncLockMap = new ConcurrentHashMap<>();
|
||||
|
||||
protected final List<CachedAction> actions = new CopyOnWriteArrayList<>();
|
||||
|
||||
@@ -232,7 +232,7 @@ public class CachedManagerService implements CachedManager, CachedActionFunc, Se
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理指定缓存key的{@link org.redkale.cached.spi.CachedAction}
|
||||
* 处理指定缓存名称的{@link org.redkale.cached.spi.CachedAction}
|
||||
*
|
||||
* @param name 缓存名称
|
||||
* @param consumer 处理函数
|
||||
|
||||
@@ -54,11 +54,15 @@ public class CachedManagerTest {
|
||||
Assertions.assertEquals(
|
||||
manager.localGet("name", bean.getName(), CachingBean.class).toString(), json);
|
||||
|
||||
manager.localGetSet("group", "key1", CachingBean.class, true, 2, expire, () -> new CachingBean("v1", "r1"));
|
||||
manager.localGetSet("group", "key1", CachingBean.class, true, 3, expire, () -> new CachingBean("v1", "r1"));
|
||||
Utility.sleep(2);
|
||||
manager.localGetSet("group", "key2", CachingBean.class, true, 2, expire, () -> new CachingBean("v2", "r2"));
|
||||
manager.localGetSet("group", "key2", CachingBean.class, true, 3, expire, () -> new CachingBean("v2", "r2"));
|
||||
Utility.sleep(2);
|
||||
manager.localGetSet("group", "key3", CachingBean.class, true, 2, expire, () -> new CachingBean("v3", "r3"));
|
||||
manager.localGetSet("group", "key3", CachingBean.class, true, 3, expire, () -> new CachingBean("v3", "r3"));
|
||||
Utility.sleep(2);
|
||||
manager.localGetSet("group", "key4", CachingBean.class, true, 3, expire, () -> new CachingBean("v4", "r4"));
|
||||
Assertions.assertEquals(3, manager.getLocalSource().getSize("group"));
|
||||
manager.getLocalSource().updateLimit("group", 2);
|
||||
Assertions.assertEquals(2, manager.getLocalSource().getSize("group"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user