Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Images are Getting cached in UWP application

In my UWP application I am binding the images from azure. It is getting cached when it get the response. When I change the image in the azure it's not reflecting in my UI, Instead it display the image from cache. Is there any way to clear the cache of my UWP application or to restrict the application to cache images?.

like image 257
Vishnu s Avatar asked Mar 09 '23 14:03

Vishnu s


1 Answers

Have you tried CreateOptions="IgnoreImageCache"?

<Image>
    <Image.Source>
        <BitmapImage UriSource="{Binding Url}" 
                     CreateOptions="IgnoreImageCache" 
                     DecodePixelWidth="120" 
                     DecodePixelHeight="120" />
    </Image.Source>
</Image>

But make sure you set the proper decode pixel width/height to avoid using unnecessary memory.

According to the documentation -

You should only use BitmapCreateOptions.IgnoreImageCache in cases where you know that the source image file as retrieved by Uniform Resource Identifier (URI) has the potential to change over time. Otherwise, setting CreateOptions to use BitmapCreateOptions.IgnoreImageCache causes all newly retrieved image sources to be decoded again, which can negatively impact performance.

So maybe try setting None as the default value for CreateOptions, and only update it to IgnoreImageCache once you are absolutely sure that the image has been updated by the cloud. Note CreateOptions is also a dependency property, so you should be able to use data binding too.

like image 91
Justin XL Avatar answered Mar 23 '23 21:03

Justin XL