Xamarin 表单:图像缓存

Xamarin forms: Image Cache

您好,我正在尝试使用 xamarin 表单构建一个应用 PCL。我正在实现我在其中使用默认图像的图像库。所有图像都在 blob 上。我想下载图像并将该图像缓存在设备中,下载完成后我需要用它替换我的默认图像。 下次加载应用程序时,仅当缓存中不存在图像时才下载图像。 我没有得到任何用于图像缓存和从缓存加载图像的插件。 我见过一个名为 FFFPLUGIN 的插件,但它没有用。 知道我该如何实现吗?图片缓存

您可以在此处显示的 Xamarin Forms 中使用内置 ImageCaching

https://developer.xamarin.com/guides/xamarin-forms/working-with/images/#Downloaded_Image_Caching

Downloaded Image Caching

UriImageSource also supports caching of downloaded images, configured through the following properties:

CachingEnabled - Whether caching is enabled ( true by default).

CacheValidity - A TimeSpan that defines how long the image will be stored locally. Caching is enabled by default and will store the image locally for 24 hours. To disable caching for a particular image, instantiate the image source like this:

Image.Source = new UriImageSource {CachingEnabled = false,
Uri="http://server.com/image"}; To set a specific cache period (for
example, 5 days) instantiate the image source like this:


webImage.Source = new UriImageSource {
Uri = new Uri("https://xamarin.com/content/images/pages/forms/example-app.png"),
CachingEnabled = true,
CacheValidity = new TimeSpan(5,0,0,0) };

Built-in caching makes it very easy to support scenarios like scrolling lists of images, where you can set (or bind) an image in each cell and let the built-in cache take care of re-loading the image when the cell is scrolled back into view.