1 0 Tag Archives: cache
post icon

Silverlight Tip of the Day #16 – Working with IgnoreImageCache

If you have ever tried to work with the property IgnoreImageCache you might have noticed it does not work as you might expect it to.

In MSDN this property is stated to have the following purpose:

Loads images without using an existing image cache. This option should only be selected when images in a cache need to be refreshed.

What’s not clear is while this will cause Silverlight to ignore its internal cache the same can not be said for your browsers cache. So, if your browser has decided to cache the image by its URI it may return the same file to Silverlight even if the file was changed on the server.

One way to get around this is to try to manipulate the URI in order to get past the browser’s rules for caching files. Check out this blog for an example on how to implement this:

http://developers.de/blogs/damir_dobric/archive/2009/11/30/how-to-prevent-caching-of-images-in-silverlight.aspx

If you are not familiar with how to use IgnoreImageCache I have include a code snippet below that shows you to change the Silverlight caching to ignore the cache when a bitmap is loaded:

MainPage.xaml:

<Button Click="Button_Click" Content="Load Image"/>
 
<Image x:Name="MyImage"/>

 

MainPage.xaml.cs:

private void Button_Click(object sender, RoutedEventArgs e) 
{ 
    MyImage.Source = null; 
    Uri uri = new 
Uri(http://www.arcticstockimages.com/wp-content/uploads/2009/10/iceberg_1920x1200.jpg, 
UriKind.Absolute); 
    BitmapImage bi = new BitmapImage(uri); 
    bi.CreateOptions = BitmapCreateOptions.IgnoreImageCache; 
    MyImage.Source = bi; 
}

Thank you,

–Mike

Leave a Comment