您可以使用ImageLoaderConfiguration.Builder(上下文)的方法diskCache()來爲通用圖像加載器設置DiskCache。而這個定製的磁盤緩存可能更喜歡內部緩存。
而且我們可以通過Universal-Image-Loader(其StorageUtils)的公共方法創建內部存儲。
例如,
// false to indicator we don't prefer external storage.
File cacheDir = StorageUtils.getCacheDirectory(context, false);
// to avoid exception, we still prepare a default one as universal image loader
File reserveCacheDir = StorageUtils.getCacheDirectory(context);
long cacheMaxSize = 15 * 1024 * 1024; // 15 MB
DiskCache diskCache;
try {
diskCache = new LruDiscCache(cacheDir, reserveCacheDir, DefaultConfigurationFactory.createFileNameGenerator(), cacheMaxSize, 0);
} catch (IOException e) {
e.printStackTrace();
// if we cannot use LruDiscCache with internal cache, jut use DefaultConfigurationFactory instead
diskCache = DefaultConfigurationFactory.createDiskCache(context, DefaultConfigurationFactory.createFileNameGenerator(), cacheMaxSize, 0);
}
ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(context)
.diskCache(diskCache);
ImageLoaderConfiguration config = builder.build();
ImageLoader.getInstance().init(config);
希望這可能是對你有用。