Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed the removeObject method key-value pair removal issue #2960

Merged
merged 1 commit into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public Object getObject(Object key) {

@Override
public Object removeObject(Object key) {
keyMap.remove(key);
return delegate.removeObject(key);
}

Expand Down
17 changes: 17 additions & 0 deletions src/test/java/org/apache/ibatis/cache/LruCacheTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import org.apache.ibatis.cache.impl.PerpetualCache;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Field;
import java.util.Map;

class LruCacheTest {

@Test
Expand Down Expand Up @@ -60,4 +63,18 @@ void shouldFlushAllItemsOnDemand() {
assertNull(cache.getObject(4));
}

@Test
void shouldCacheSizeEqualsKeyMapSize() throws Exception {
LruCache cache = new LruCache(new PerpetualCache("default"));
cache.setSize(5);
for (int i = 0; i < 5; i++) {
cache.putObject(i, i);
}
cache.removeObject(1);
Field keyMap = cache.getClass().getDeclaredField("keyMap");
keyMap.setAccessible(true);
Map<Object, Object> map = (Map<Object, Object>) keyMap.get(cache);
assertEquals(map.size(), cache.getSize());
}

}