4

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?

John McKenzie
  • 420
  • 6
  • 16

3 Answers3

7

Use .noCache() to bypass caches.

koush
  • 2,972
  • 28
  • 31
  • I tried .noCache() but I seem to get a Cannot Resolve Method .noCache() error. – John McKenzie Nov 21 '14 at 19:26
  • 1
    You'll need to use the longform then that lets you modify http parameters: Ion.with(context) .load(url) .noCache() .withBitmap() .placeholder.error.load.... – koush Nov 21 '14 at 23:07
7

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);
David Manpearl
  • 12,362
  • 8
  • 55
  • 72
3

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.

Ivan Wooll
  • 4,145
  • 3
  • 23
  • 34
  • 1
    The problem is I don't have any control over the url link itself unfortunately, otherwise that would be a great idea. – John McKenzie Nov 09 '14 at 18:18
  • 2
    Sorry I mean locally when you make your call. Just append an imaginary parameter to the end of your url. e.g. "http://yoursite.com?uniqueid="+timestamp – Ivan Wooll Nov 09 '14 at 18:20
  • Oh right, I would never of thought of that, haha worked perfect mate, thanks heaps!! Appreciated!! – John McKenzie Nov 09 '14 at 18:32