mirror of
https://github.com/PowerJob/PowerJob.git
synced 2025-07-17 00:00:04 +08:00
[fix] fix the bug of LRUCache oversize
This commit is contained in:
parent
4cbbc0a2c1
commit
ea4fecc270
@ -19,7 +19,7 @@ public class LRUCache<K, V> {
|
||||
public LRUCache(int cacheSize) {
|
||||
innerCache = CacheBuilder.newBuilder()
|
||||
.concurrencyLevel(2)
|
||||
.initialCapacity(cacheSize)
|
||||
.maximumSize(cacheSize)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user