From 98a0d27a5f4c46efcf768ee79f04f4d3bb38ab94 Mon Sep 17 00:00:00 2001 From: JessYan Date: Thu, 14 Jun 2018 17:27:44 +0800 Subject: [PATCH] Improve IntelligentCache --- .../arms/integration/cache/IntelligentCache.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arms/src/main/java/com/jess/arms/integration/cache/IntelligentCache.java b/arms/src/main/java/com/jess/arms/integration/cache/IntelligentCache.java index 1332d66..f940384 100644 --- a/arms/src/main/java/com/jess/arms/integration/cache/IntelligentCache.java +++ b/arms/src/main/java/com/jess/arms/integration/cache/IntelligentCache.java @@ -53,7 +53,7 @@ public class IntelligentCache implements Cache { * @return 相加后的 {@code size} */ @Override - public int size() { + public synchronized int size() { return mMap.size() + mCache.size(); } @@ -63,7 +63,7 @@ public class IntelligentCache implements Cache { * @return 相加后的 {@code maxSize} */ @Override - public int getMaxSize() { + public synchronized int getMaxSize() { return mMap.size() + mCache.getMaxSize(); } @@ -75,7 +75,7 @@ public class IntelligentCache implements Cache { */ @Nullable @Override - public V get(String key) { + public synchronized V get(String key) { if (key.startsWith(KEY_KEEP)) { return mMap.get(key); } @@ -91,7 +91,7 @@ public class IntelligentCache implements Cache { */ @Nullable @Override - public V put(String key, V value) { + public synchronized V put(String key, V value) { if (key.startsWith(KEY_KEEP)) { return mMap.put(key, value); } @@ -106,7 +106,7 @@ public class IntelligentCache implements Cache { */ @Nullable @Override - public V remove(String key) { + public synchronized V remove(String key) { if (key.startsWith(KEY_KEEP)) { return mMap.remove(key); } @@ -120,7 +120,7 @@ public class IntelligentCache implements Cache { * @return {@code true} 为在容器中含有这个 {@code key}, 否则为 {@code false} */ @Override - public boolean containsKey(String key) { + public synchronized boolean containsKey(String key) { if (key.startsWith(KEY_KEEP)) { return mMap.containsKey(key); } @@ -133,7 +133,7 @@ public class IntelligentCache implements Cache { * @return 合并后的 {@code keySet} */ @Override - public Set keySet() { + public synchronized Set keySet() { Set set = mCache.keySet(); set.addAll(mMap.keySet()); return set; -- GitLab