Android Ion Cache Refresh

2020-07-17 06:04发布

I'm using a specific url to obtain an image online, but the url itself automatically changes every few minutes. I'm using ION library from Here The problem I'm having is when I refresh the page, the page itself looks like it is refreshing but the exact same picture is appearing. I'm assuming its a cached image? If I reinstall the application, then it obtains the correct image again.

This is how I'm using ION where imageID2[position] is just a typical url to a jpg.

    Ion.with(imageView)
            .placeholder(R.drawable.ic_launcher)
            .error(R.drawable.ic_launcher)
            .load(imageId2[position]);

Is there anyway I can disable the cache or just make it refind the images again?

3条回答
等我变得足够好
2楼-- · 2020-07-17 06:39

You can append a unique string to your url for example a current timestamp in order to force Ion to treat each request as unique.

查看更多
倾城 Initia
3楼-- · 2020-07-17 06:40

Use .noCache() to bypass caches.

查看更多
不美不萌又怎样
4楼-- · 2020-07-17 06:52

As per documentation here, use the "long" way to build an ImageView request so that you can add headers, noCache, etc.

Change your original request from this:

Ion.with(imageView)
        .placeholder(R.drawable.ic_launcher)
        .error(R.drawable.ic_launcher)
        .load(urlString);

To this:

Ion.with(context)
        .load(urlString)
        .noCache()
        .withBitmap()
        .placeholder(R.drawable.ic_launcher)
        .error(R.drawable.ic_launcher)
        .intoImageView(imageView);
查看更多
登录 后发表回答