Last active
August 29, 2015 14:19
-
-
Save TWiStErRob/d8da8038fc85d6363ad8 to your computer and use it in GitHub Desktop.
Glide DiskCache.Factory implementation to use the context-provided externalCacheDir
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
import java.io.File; | |
import android.content.Context; | |
import com.bumptech.glide.load.engine.cache.*; | |
public final class ExternalCacheDiskCacheFactory implements DiskCache.Factory { | |
private final Context context; | |
private final String diskCacheName; | |
private final int diskCacheSize; | |
public ExternalCacheDiskCacheFactory(Context context, int diskCacheSize) { | |
this(context, null /*diskCacheName*/, diskCacheSize); | |
} | |
public ExternalCacheDiskCacheFactory(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 = new File(context.getExternalCacheDir(), diskCacheName); | |
} else { | |
cacheDir = context.getExternalCacheDir(); | |
} | |
if (cacheDir != null) { | |
diskCache = DiskLruCacheWrapper.get(cacheDir, diskCacheSize); | |
} | |
// only needed before 3.6.0, see https://github.com/bumptech/glide/issues/374 | |
// if (diskCache == null) { | |
// diskCache = new DiskCacheAdapter(); | |
// } | |
return diskCache; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment