我正在使用通用图像库 (UIL) 在我的应用程序中加载图像。
现在的问题是我可以在同一个 URL 上使用不同的图像。我的意思是今天我在 URL 中有一张猫图片,明天我可能在同一个 URL 中有一张狗图片。所以我想检查缓存图像是否存在 2 天,然后将其删除并再次下载图像。
这是我的配置。
File cacheDir = StorageUtils.getOwnCacheDirectory(this, "FriendListCache");
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
// You can pass your own memory cache implementation
.diskCache(new UnlimitedDiscCache(cacheDir))
.diskCacheFileNameGenerator(new HashCodeFileNameGenerator())
.build();
ImageLoader.getInstance().init(config);
这是图像加载选项。
imageLoader = ImageLoader.getInstance();
options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.medium_load)
.cacheInMemory(true)
.cacheOnDisk(true)
.imageScaleType(ImageScaleType.EXACTLY_STRETCHED)
.decodingOptions(resizeOptions)
.displayer(new RoundedBitmapDisplayer(160))
.build();
最佳答案
UIL 为您的要求提供LimitedAgeDiscCache选项。
LimitedAgeDiscCache(具有有限文件生命周期的大小无限缓存。如果缓存文件的年龄超过定义的限制,那么它将从缓存中删除。)
.discCache(new LimitedAgeDiscCache(cacheDir, 14400))
关于android - 在 android 中 2 天后使 UIL 缓存图像过期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27740642/