#2677 - Add ReentrantLock for DefaultServerCache.runEviction() and trigger runEviction() via mutationCounter

If we get a lot of cache mutation (puts) between background trims then also trigger runEviction() in foreground using mutationCounter.
This commit is contained in:
Rob Bygrave
2022-05-02 21:48:58 +12:00
parent 1cd319c495
commit 5c332286b6
2 changed files with 75 additions and 62 deletions
@@ -17,7 +17,7 @@ class DefaultServerCache_RunEvictionTest {
cacheOptions.setMaxSize(300);
cacheOptions.setMaxIdleSecs(1);
cacheOptions.setMaxSecsToLive(2);
cacheOptions.setTrimFrequency(1);
cacheOptions.setTrimFrequency(5);
ServerCacheConfig con = new ServerCacheConfig(ServerCacheType.BEAN, "foo", "foo", cacheOptions, null, null);
return new DefaultServerCache(new DefaultServerCacheConfig(con));
@@ -44,10 +44,10 @@ class DefaultServerCache_RunEvictionTest {
}
private void doStuff() {
for (int i = 0; i < 500; i++) {
for (int i = 0; i < 5000; i++) {
String key = "" + random.nextInt(20000);
int mode = random.nextInt(10);
if (mode < 8) {
if (mode < 7) {
cache.get(key);
} else {
cache.put(key, key + "-" + System.currentTimeMillis());