0

在我的 Xamarin 应用程序中,我在服务器上上传了一个新的“用户配置文件”图像,然后我尝试使用新版本的图像更新图像(注意到图像 uri 仍然相同)。

Xamarin 提供了一个图像缓存,我需要使其无效以强制从服务器重新加载图像。但似乎无法使图像缓存失效!我找不到解决办法!

我尝试了几种解决方案,但没有办法!即使我重新启动应用程序,我也会得到旧版本的图像。

我尝试过一些这样的东西:

(MediaImageSource 作为 UriImageSource).CacheValidity = new TimeSpan(-1); FFImageLoading.Forms.CachedImage.InvalidateCache(MediaImageSource, FFImageLoading.Cache.CacheType.All, true); FFImageLoading.ImageService.Instance.InvalidateCacheAsync(FFImageLoading.Cache.CacheType.All);

但没有任何工作,欢迎任何想法?谢谢

4

2 回答 2

2

我执行以下操作:

// this.Img is the FFImageLoading.CachedImage in my view
var source = this.Img.Source as FileImageSource;

// Reset cache using the global instance (the key is the file name, I assume it is the uri for UriImageSource)
await ImageService.Instance.InvalidateCacheEntryAsync( source.File, CacheType.All, true );

// Reassign the image source (since the binding has not changed per se, the UI may miss the change otherwise)
this.Img.Source = new FileImageSource(...);

这会重新加载图像,并且 FFImageLoading 甚至会在它发生变化时做出漂亮的淡入淡出动画。

于 2018-10-17T23:14:33.923 回答
0

实际上有一个静态方法CachedImage可以接受 的任何孩子ImageSource,因此无需猜测密钥:

FFImageLoading.Forms.CachedImage.InvalidateCache(myImageSource, CacheType.All, true);
于 2021-11-25T17:30:39.263 回答