Skip to content

Commit 569ec6c

Browse files
committed
update LruMemoryCache
1 parent 30c6cf9 commit 569ec6c

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

library/src/com/lidroid/xutils/cache/KeyExpiryMap.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public synchronized Long put(K key, Long expiryTimestamp) {
6868
public synchronized boolean containsKey(Object key) {
6969
boolean result = false;
7070
if (super.containsKey(key)) {
71-
if (System.currentTimeMillis() < super.get(key)) {
71+
Long expiryTimestamp = super.get(key);
72+
if (expiryTimestamp != null && System.currentTimeMillis() < expiryTimestamp) {
7273
result = true;
7374
} else {
7475
this.remove(key);

library/src/com/lidroid/xutils/cache/LruMemoryCache.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,13 @@ public final V get(K key) {
6969
throw new NullPointerException("key == null");
7070
}
7171

72-
// If expired, remove the entry.
73-
if (!keyExpiryMap.containsKey(key)) {
74-
this.remove(key);
75-
return null;
76-
}
77-
7872
V mapValue;
7973
synchronized (this) {
74+
// If expired, remove the entry.
75+
if (!keyExpiryMap.containsKey(key)) {
76+
this.remove(key);
77+
return null;
78+
}
8079
mapValue = map.get(key);
8180
if (mapValue != null) {
8281
hitCount++;

0 commit comments

Comments
 (0)