Page view counter

Silverlight Tips of the Day - Blog by Mike Snow

Game Programming with Silverlight

Silverlight Tip of the Day #102 - Bypassing the Image Cache

By default Silverlight will not download an image more than once if is contained within the image cache. That is, as long as the URI remains the same it will reference the image from the cache.

So what if the image changed on the server even though it has the same URI? Your application can force an update by setting the property IgnoreImageCache to true.

Example:

Image img = new Image();
Uri uri = new Uri("http://YourServer.com/MyImage.png", UriKind.Absolute);
BitmapImage bi = new System.Windows.Media.Imaging.BitmapImage(uri);
bi.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
img.Source = bi;
LayoutRoot.Children.Add(img);

Thank you,
--Mike Snow

 Subscribe in a reader

Comments

Microsoft Weblogs said:

By default Silverlight will not download an image more than once if is contained within the image cache

# March 25, 2009 1:55 PM

GearWorld said:

Yeah and what you do is waiting for everybody to have downloaded the new images then you remove the IgnoreImageCache so it doesn't send the image everytime ?

# March 25, 2009 4:43 PM

mike.snow said:

Yes. For example, you can program your app to have a "refresh" button that refershes the images only when the button is pressed. Or something similiar...

# March 25, 2009 4:48 PM

tgrand said:

Isn't this why browser caches are supposed to use things like timestamps, serial numbers, and expiration dates?  Are you saying those mechanisms are ineffective or not used when downloading images with SL?

# March 26, 2009 10:30 AM

mike.snow said:

I believe they are effective but if this is useful if your app needs to update the images before the expiration date occurs.

# March 26, 2009 10:35 AM

Eric Willeke said:

Is this SL3? You have it tagged with both, but I've never noticed this in SL2.

# March 26, 2009 1:34 PM

mike.snow said:

Sorry, yes this is just SL3. I didn't mean to tag Sl2.

# March 26, 2009 2:40 PM

Eric Willeke said:

So, what other image options are there now? I'm the architect on Inkubook.com, and we do a LOT of image manipulation all things considered. I haven't, unfortunately, taken the time to dig into the new parts yet, mostly just checking for upgrade compatability with the current site.

# March 27, 2009 1:31 PM

mike.snow said:

I'll have to look into it myself. This is the only new one I am aware of. Thanks.

# March 30, 2009 12:36 PM

Visual Web Developer Team Blog said:

Most Recent Posts: Silverlight Tip of the Day #106 - Setting Default Browser from within VS Silverlight

# April 6, 2009 6:13 PM

Silverlight Tips of the Day - Blog by Mike Snow said:

The purpose of this post is to create an outline summary all the blogs from my Silverlight Tips of the

# April 6, 2009 6:20 PM

Бюллетень cильверлайтера said:

Бюллетень Сильверлайтера. Выпуск №2. 9 Мая 2009 года. Здравствуйте, уважаемые сильверлайтеры! Вот и прошёл

# May 9, 2009 10:50 AM

NewsPeeps said:

Thank you for submitting this cool story - Trackback from NewsPeeps

# August 8, 2009 6:36 PM

Silverlight Tip of the Day #102 - Bypassing the Image Cache … Silverlight Blog said:

Pingback from  Silverlight Tip of the Day #102 - Bypassing the Image Cache … Silverlight Blog

# November 3, 2009 6:30 PM

MoiFou said:

The MSDN topic at msdn.microsoft.com/.../system.windows.media.imaging.bitmapcreateoptions(VS.95).aspx has this description of the IgnoreImageCache parameter of the BitmapCreateOptions enum:

"Loads images without using an existing image cache. This option should only be selected when images in a cache need to be refreshed.... When IgnoreImageCache is selected, any existing entries in the image cache are replaced, even if they share the same URI."

I can't seem to reconcile this description.  It seems to contradict itself, and your tip.  

Can you tell me, if IgnoreImageCache is set, is the image contained in the BitmapImage or BitmapSource object in the image cache, or outside of the image cache?  If it's outside, why would "existing entries in the image cache are replaced"?

Thanks for any help.

# November 25, 2009 12:10 AM