Images are Getting cached in UWP application

流过昼夜 提交于 2019-12-13 12:22:01

问题


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?.


回答1:


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.



来源:https://stackoverflow.com/questions/45143530/images-are-getting-cached-in-uwp-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!