[fix] fix the bug of LRUCache oversize

This commit is contained in:
tjq 2020-06-26 20:45:20 +08:00
parent 4cbbc0a2c1
commit ea4fecc270
2 changed files with 24 additions and 1 deletions

View File

@ -19,7 +19,7 @@ public class LRUCache<K, V> {
public LRUCache(int cacheSize) {
innerCache = CacheBuilder.newBuilder()
.concurrencyLevel(2)
.initialCapacity(cacheSize)
.maximumSize(cacheSize)
.build();
}

View File

@ -0,0 +1,23 @@
package com.github.kfcfans.powerjob.function;
import com.github.kfcfans.powerjob.worker.common.utils.LRUCache;
import org.junit.jupiter.api.Test;
/**
* LRU cache test
*
* @author tjq
* @since 2020/6/26
*/
public class LRUCacheTest {
@Test
public void testCache() {
LRUCache<Long, String> cache = new LRUCache<>(10);
for (long i = 0; i < 100; i++) {
cache.put(i, "STR:" + i);
}
cache.forEach((x, y) -> System.out.println("key:" + x));
}
}