Stop image caching in wP7

1.2k Views Asked by At

I have a function which displays images from a binded uri (ie; www.website.com/picture1.jpg).

I have found and now understand that the phone caches the images that are downloaded. I read that its only for the life of the runng of the app, but even when I close the app and go back into it the same images from the cache come up. Is there a way to stop this caching happening at all for this particular page?

EDIT: The images update regularly, but still have the same name, hence the need not to cache. Think security camera for example.

Many thanks.

5

There are 5 best solutions below

3
On BEST ANSWER

There's no way around it unless you add a random query string to the image uri on each GET i.e.

var imageUrl = "www.website.com/picture1.jpg";
var imageUri = new Uri(String.Format("{0}?{1}", imageUrl, Guid.NewGuid()));

The caching is a little too aggressive - If doing a GET to the same Uri on any http request for the applications life cycle - Even if the content changes every time - The phone will cache it. It kept me puzzled for hours when I was trying to talk to a JSON-RPC web service...

Of course in general you will want images to be cached - But if you're sure the images you're after will be changing frequently then the above will work.

0
On

Add a unique querystring parameter to the URL. (eg, DateTime.Now)

0
On

Depending on if you have control over the website and its content; shouldn't this be handled by setting the HTTP Response headers? I would assume the platform respects the headers (unverified).

Otherwise the above posted random string trick will work.

0
On

There is CreateOptions property on BitmapImage (if you are loading in code) which lets you specify BitmapCreateOptions,one of which is IgnoreImageCache: Loads images without using an existing image cache. This option should only be selected when images in a cache need to be refreshed.

I've not tried it out, but it sounds like the kind of thing you are looking for ... if you do try it, I'd be interested in the result.

0
On

Cache is a good thing , cause in your case, it can save the cost to download the image, if the image is not change, why you need to download it again?

if your image had been changed, and you want to enforce to download it again, you can generate a unique id at the url.

but think about it, why?