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);
희망.