关于java:在磁盘Android Universal Image Loader上设置最大缓存大小

Set Max Cache Size on Disk Android Universal Image Loader

我在项目中使用的是Android Universal Image Loader。我的项目中有2500个映像,它们需要80 MB以上的磁盘空间。有什么办法可以限制磁盘缓存大小?

https://github.com/nostra13/Android-Universal-Image-Loader


是的,您可以确定内存和磁盘缓存的大小:

来自图书馆的文档

1
2
3
ImageLoaderConfiguration config = new
ImageLoaderConfiguration .Builder(getApplicationContext())
.discCache(new UnlimitedDiscCache(cacheDir))

然后,作者进一步解释了discCache的其他选项:

Using discCache(), you can define cash implementation in the file system. You can use ready-made solutions (where the files matching certain URLs are named as hash codes of these URLs):

1 - UnlimitedDiscCache (usual cache, no restrictions)

2 - FileCountLimitedDiscCache (cache with limited files number)

3 - TotalSizeLimitedDiscCache (cache with limited size)

您还可以拥有自己的磁盘和内存缓存实现,有关更多信息,请参见我先前提供的链接。