Skip to content

Commit ac91f95

Browse files
jiaoleiwyouflf
authored andcommitted
update LruDiskCache
1 parent 7de7f31 commit ac91f95

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

library/src/com/lidroid/xutils/bitmap/core/BitmapCache.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class BitmapCache {
3939
private LruMemoryCache<MemoryCacheKey, Bitmap> mMemoryCache;
4040

4141
private final Object mDiskCacheLock = new Object();
42-
private boolean isDiskCacheReadied = false;
42+
private volatile boolean isDiskCacheReady = false;
4343

4444
private BitmapGlobalConfig globalConfig;
4545

@@ -106,8 +106,8 @@ public void initDiskCache() {
106106
}
107107
}
108108
}
109-
isDiskCacheReadied = true;
110109
mDiskCacheLock.notifyAll();
110+
isDiskCacheReady = true;
111111
}
112112
}
113113

@@ -142,7 +142,7 @@ public Bitmap downloadBitmap(String uri, BitmapDisplayConfig config, final Bitma
142142
if (globalConfig.isDiskCacheEnabled()) {
143143
synchronized (mDiskCacheLock) {
144144
// Wait for disk cache to initialize
145-
while (!isDiskCacheReadied) {
145+
while (!isDiskCacheReady) {
146146
try {
147147
mDiskCacheLock.wait();
148148
} catch (Throwable e) {
@@ -257,7 +257,7 @@ public File getBitmapFileFromDiskCache(String uri) {
257257
public Bitmap getBitmapFromDiskCache(String uri, BitmapDisplayConfig config) {
258258
if (uri == null || !globalConfig.isDiskCacheEnabled()) return null;
259259
synchronized (mDiskCacheLock) {
260-
while (!isDiskCacheReadied) {
260+
while (!isDiskCacheReady) {
261261
try {
262262
mDiskCacheLock.wait();
263263
} catch (Throwable e) {
@@ -317,7 +317,7 @@ public void clearDiskCache() {
317317
LogUtils.e(e.getMessage(), e);
318318
}
319319
mDiskLruCache = null;
320-
isDiskCacheReadied = false;
320+
isDiskCacheReady = false;
321321
}
322322
}
323323
initDiskCache();

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,16 @@ public synchronized long getExpiryTimestamp(String key) throws IOException {
424424

425425
public File getCacheFile(String key, int index) {
426426
String diskKey = fileNameGenerator.generate(key);
427-
return new File(this.directory, diskKey + "." + index);
427+
File result = new File(this.directory, diskKey + "." + index);
428+
if (result.exists()) {
429+
return result;
430+
} else {
431+
try {
432+
this.remove(key);
433+
} catch (IOException ignore) {
434+
}
435+
return null;
436+
}
428437
}
429438

430439
public Snapshot get(String key) throws IOException {

0 commit comments

Comments
 (0)