-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use factory to lazily instantiate disk cache.
Fixes #298
- Loading branch information
Showing
7 changed files
with
138 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...ary/src/main/java/com/bumptech/glide/load/engine/cache/InternalCacheDiskCacheFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.bumptech.glide.load.engine.cache; | ||
|
||
import android.content.Context; | ||
|
||
import com.bumptech.glide.Glide; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* Creates an {@link com.bumptech.glide.disklrucache.DiskLruCache} based disk cache in the internal disk cache | ||
* directory. | ||
*/ | ||
public final class InternalCacheDiskCacheFactory implements DiskCache.Factory { | ||
private final Context context; | ||
private final String diskCacheName; | ||
private final int diskCacheSize; | ||
|
||
public InternalCacheDiskCacheFactory(Context context, int diskCacheSize) { | ||
this(context, null /*diskCacheName*/, diskCacheSize); | ||
} | ||
|
||
public InternalCacheDiskCacheFactory(Context context, String diskCacheName, int diskCacheSize) { | ||
this.context = context; | ||
this.diskCacheName = diskCacheName; | ||
this.diskCacheSize = diskCacheSize; | ||
} | ||
|
||
@Override | ||
public DiskCache build() { | ||
DiskCache diskCache = null; | ||
final File cacheDir; | ||
|
||
if (diskCacheName != null) { | ||
cacheDir = Glide.getPhotoCacheDir(context, diskCacheName); | ||
} else { | ||
cacheDir = Glide.getPhotoCacheDir(context); | ||
} | ||
|
||
if (cacheDir != null) { | ||
diskCache = DiskLruCacheWrapper.get(cacheDir, diskCacheSize); | ||
} | ||
|
||
if (diskCache == null) { | ||
diskCache = new DiskCacheAdapter(); | ||
} | ||
return diskCache; | ||
} | ||
} |