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

Vis*_*u s 3 xaml windows-store-apps uwp

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

Jus*_* XL 5

你试过CreateOptions="IgnoreImageCache"吗?

<Image>
    <Image.Source>
        <BitmapImage UriSource="{Binding Url}" 
                     CreateOptions="IgnoreImageCache" 
                     DecodePixelWidth="120" 
                     DecodePixelHeight="120" />
    </Image.Source>
</Image>
Run Code Online (Sandbox Code Playgroud)

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

根据文件-

如果您知道由统一资源标识符 (URI) 检索的源图像文件可能会随着时间的推移而改变,则您应该只使用 BitmapCreateOptions.IgnoreImageCache。否则,将 CreateOptions 设置为使用 BitmapCreateOptions.IgnoreImageCache 会导致所有新检索的图像源再次解码,这会对性能产生负面影响。

因此,也许可以尝试将 设置None为默认值CreateOptions,并且仅在IgnoreImageCache您绝对确定图像已被云更新后才将其更新为。NoteCreateOptions也是dependency property,因此您也应该能够使用数据绑定。