Android 如果从具有相同URL的服务器更改,则通用映像加载器不会刷新映像 我使用通用图像加载程序从服务器加载图像,并将其缓存到内存中以快速加载 但从服务器端使用相同的URL更新图像 例如,www.example.com/xyz.png是图像的URL,当他们需要更新图像时,会返回相同的URL和不同的图像 在本例中,Universal Image Loader返回先前缓存在内存中的图像(我认为它使用相关URL缓存了图像) 所以,若URL返回不同的图像,我需要更改图像

Android 如果从具有相同URL的服务器更改,则通用映像加载器不会刷新映像 我使用通用图像加载程序从服务器加载图像,并将其缓存到内存中以快速加载 但从服务器端使用相同的URL更新图像 例如,www.example.com/xyz.png是图像的URL,当他们需要更新图像时,会返回相同的URL和不同的图像 在本例中,Universal Image Loader返回先前缓存在内存中的图像(我认为它使用相关URL缓存了图像) 所以,若URL返回不同的图像,我需要更改图像,android,universal-image-loader,Android,Universal Image Loader,这是我用于加载图像的代码 DisplayImageOption.java 图像加载代码 感谢您在ImageLoader配置中添加diskCache选项 File cacheDir = StorageUtils.getCacheDirectory(context); long cacheAge = 10L; ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context) .diskCa

这是我用于加载图像的代码

DisplayImageOption.java 图像加载代码
感谢您在
ImageLoader配置中添加
diskCache
选项

File cacheDir = StorageUtils.getCacheDirectory(context);
long cacheAge = 10L;

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
        .diskCache(new LimitedAgeDiscCache(cacheDir, cacheAge)) // this will make the cache to remain for 10 seconds only
        .build();
然后将其设置为
ImageLoader
,并使用
DisplayImageOption

ImageLoader.getInstance().init(config);
ImageLoader.getInstance().displayImage(url, imageView, DisplayImageOption.getDisplayImage());
它的作用是什么? 取自

LimitedAgeDiscCache(大小不限的缓存,文件的生存期有限。如果缓存文件的年龄超过定义的限制,则将从缓存中删除。)

这段代码来自Android Universal Image Loader的类


您可能也喜欢这种方法。

谢谢您的回答。我也得到了这种类型的答案,但这段代码清除了我的所有图像缓存,我需要像UIL一样检查图像URL及其缓存中的数据,如果数据相同,则从缓存加载图像,如果数据不同,则清除与图像URL关联的先前缓存,然后创建新缓存。是的,看看这个
File cacheDir = StorageUtils.getCacheDirectory(context);
long cacheAge = 10L;

ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
        .diskCache(new LimitedAgeDiscCache(cacheDir, cacheAge)) // this will make the cache to remain for 10 seconds only
        .build();
ImageLoader.getInstance().init(config);
ImageLoader.getInstance().displayImage(url, imageView, DisplayImageOption.getDisplayImage());
/**
     * @param cacheDir Directory for file caching
     * @param maxAge   Max file age (in seconds). If file age will exceed this value then it'll be removed on next
     *                 treatment (and therefore be reloaded).
     */
    public LimitedAgeDiskCache(File cacheDir, long maxAge) {
        this(cacheDir, null, DefaultConfigurationFactory.createFileNameGenerator(), maxAge);
}