提交 98a0d27a 编写于 作者: J JessYan

Improve IntelligentCache

上级 e4eeb3a3
......@@ -53,7 +53,7 @@ public class IntelligentCache<V> implements Cache<String, V> {
* @return 相加后的 {@code size}
*/
@Override
public int size() {
public synchronized int size() {
return mMap.size() + mCache.size();
}
......@@ -63,7 +63,7 @@ public class IntelligentCache<V> implements Cache<String, V> {
* @return 相加后的 {@code maxSize}
*/
@Override
public int getMaxSize() {
public synchronized int getMaxSize() {
return mMap.size() + mCache.getMaxSize();
}
......@@ -75,7 +75,7 @@ public class IntelligentCache<V> implements Cache<String, V> {
*/
@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<V> implements Cache<String, V> {
*/
@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<V> implements Cache<String, V> {
*/
@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<V> implements Cache<String, V> {
* @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<V> implements Cache<String, V> {
* @return 合并后的 {@code keySet}
*/
@Override
public Set<String> keySet() {
public synchronized Set<String> keySet() {
Set<String> set = mCache.keySet();
set.addAll(mMap.keySet());
return set;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册