android - 在 android 中 2 天后使 UIL 缓存图像过期

标签 android image caching universal-image-loader

我正在使用通用图像库 (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/

相关文章:

Android Facebook SDK 3.23.0 - AndroidTV 上的 FB 登录

android - 如何在 Ubuntu 上的 LG G4 上调试我的应用程序?

android - 显示大图像但在 android 中共享小图像

android - 在 Android 中正确旋转 MapView 的最简单方法?

android - setImageBitmap() 不工作

java - 更改 .png 以使用 JpegImagesToMovie.java

python - 将图像旋转 90 度以获得多维 NumPy 数组

caching - 高速缓存未命中,TLB未命中和页面错误

python - 为什么我的 LRU 缓存未命中相同的参数?

asp.net-mvc - 使用 Umbraco CachedPartial 为不同模型缓存部分 View