gpt4 book ai didi

.net - WPF Image.Source 缓存过于激进

转载 作者:行者123 更新时间:2023-12-02 04:16:59 24 4
gpt4 key购买 nike

我有一个 System.Windows.Controls.Image 实例,并且我以编程方式设置内容,如下所示:

Uri location = new Uri(uriString);
image.Source = new BitmapImage(location);

有时我知道服务器上的图像已更改,我想刷新它,但每次重复上述代码时,我都会得到相同的图像。

这似乎是一个缓存问题,但两个明显的解决方案 - RequestCacheLevelBitmapCacheOption - 似乎什么也没做。此代码具有相同的结果:

var cachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore)) {
CacheOption = BitmapCacheOption.None
};
image.Source = new BitmapImage(location, cachePolicy);
// Still uses the cached version.

我发现强制刷新的唯一方法是将一次性查询字符串附加到 URI,这似乎有效,但也是一个完整的 hack:

Uri location = new Uri(uriString + "?nonsense=" + new Random().Next());
image.Source = new BitmapImage(location);
// This forces a refresh

如何防止这些图像被缓存和/或强制刷新?

最佳答案

我认为您需要将 BitmapImage 上的 CreateOptions 设置为:

BitmapCreateOptions.IgnoreImageCache

关于.net - WPF Image.Source 缓存过于激进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4137469/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com