图像正在 UWP 应用程序中缓存

Images are Getting cached in UWP application

在我的 UWP 应用程序中,我绑定了来自 azure 的图像。它在收到响应时被缓存。当我更改 azure 中的图像时,它不会反映在我的 UI 中,而是显示缓存中的图像。 有没有办法清除我的 UWP 应用程序的缓存或限制应用程序缓存图像?

你试过了吗CreateOptions="IgnoreImageCache"

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

但请确保设置正确的解码像素 width/height 以避免使用不必要的内存。

根据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.

所以也许可以尝试将 None 设置为 CreateOptions 的默认值,并且只有在您完全确定图像已被云更新后才将其更新为 IgnoreImageCache。注意 CreateOptions 也是一个 dependency property,因此您应该也可以使用数据绑定。