Skip to content

Commit

Permalink
update LruDiskCache
Browse files Browse the repository at this point in the history
  • Loading branch information
jiaolei authored and wyouflf committed Jun 20, 2014
1 parent 7de7f31 commit ac91f95
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 5 additions & 5 deletions library/src/com/lidroid/xutils/bitmap/core/BitmapCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class BitmapCache {
private LruMemoryCache<MemoryCacheKey, Bitmap> mMemoryCache;

private final Object mDiskCacheLock = new Object();
private boolean isDiskCacheReadied = false;
private volatile boolean isDiskCacheReady = false;

private BitmapGlobalConfig globalConfig;

Expand Down Expand Up @@ -106,8 +106,8 @@ public void initDiskCache() {
}
}
}
isDiskCacheReadied = true;
mDiskCacheLock.notifyAll();
isDiskCacheReady = true;
}
}

Expand Down Expand Up @@ -142,7 +142,7 @@ public Bitmap downloadBitmap(String uri, BitmapDisplayConfig config, final Bitma
if (globalConfig.isDiskCacheEnabled()) {
synchronized (mDiskCacheLock) {
// Wait for disk cache to initialize
while (!isDiskCacheReadied) {
while (!isDiskCacheReady) {
try {
mDiskCacheLock.wait();
} catch (Throwable e) {
Expand Down Expand Up @@ -257,7 +257,7 @@ public File getBitmapFileFromDiskCache(String uri) {
public Bitmap getBitmapFromDiskCache(String uri, BitmapDisplayConfig config) {
if (uri == null || !globalConfig.isDiskCacheEnabled()) return null;
synchronized (mDiskCacheLock) {
while (!isDiskCacheReadied) {
while (!isDiskCacheReady) {
try {
mDiskCacheLock.wait();
} catch (Throwable e) {
Expand Down Expand Up @@ -317,7 +317,7 @@ public void clearDiskCache() {
LogUtils.e(e.getMessage(), e);
}
mDiskLruCache = null;
isDiskCacheReadied = false;
isDiskCacheReady = false;
}
}
initDiskCache();
Expand Down
11 changes: 10 additions & 1 deletion library/src/com/lidroid/xutils/cache/LruDiskCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,16 @@ public synchronized long getExpiryTimestamp(String key) throws IOException {

public File getCacheFile(String key, int index) {
String diskKey = fileNameGenerator.generate(key);
return new File(this.directory, diskKey + "." + index);
File result = new File(this.directory, diskKey + "." + index);
if (result.exists()) {
return result;
} else {
try {
this.remove(key);
} catch (IOException ignore) {
}
return null;
}
}

public Snapshot get(String key) throws IOException {
Expand Down

0 comments on commit ac91f95

Please sign in to comment.