By default Bitmap Images are cached by WinRT with no intervention required by the developer. Often times this is a good thing but there are some occasions where this is undesirable. Although there doesn’t appear to be any obvious control in the API reference I have found that adding a dummy querystring to the BitMapImage source filename reference does the trick and also can offer precise control over the length of caching required (if any) .
Here is how I currently manage caching in a project and limit it to being refreshed once every hour:
In My App.Config I set up a static variable:
public static String CacheOffset = "?Cache=" + ; System.DateTime.Now.DayOfYear.ToString() + ; System.DateTime.Now.Hour.ToString();
When I populate my local collection I then use something like:
This way the images are cached for the duration of the users WinRT session and also up to an hour beyond the initial population of my data collection. Obviously I can vary this duration using different parameters from the current system date and time. For instance the following would ensure that effectively no caching is carried out between user sessions:
public static String CacheOffset = "?Cache=" + ; System.DateTime.Now.Ticks.ToString() ;
If you wanted to update the image during a session then it would simply be a case of populating your image source using a different ‘virtual cache’ value for CacheOffset.
I suspect there may be better ways to achieve the same objective but for now this works for me.