如何缓存Firebase存储下载的图像 [英] How to cache Firebase storage downloaded images

查看:132
本文介绍了如何缓存Firebase存储下载的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个需要缓存图像的应用程序,以便在用户脱机时可以检索它们,并且在用户关闭并重新打开该应用程序后也应该可以访问它们.

I am developing an app where I need to cache images such that I can retrieve them when the user is offline and they should also be accessible once the user closes and reopens the app.

我需要

FirebaseFirestoreSettings.setPersistenceEnables(true)

我的问题是我找不到正确的方法.

My problem is that I can not find a proper way of doing it.

  • 我尝试将图片保存到LruCache,但是在关闭应用程序后,所有缓存的数据都会被删除.
  • 我可以将图片保存到文件中并进行检索,但是我不希望用户访问这些图片,因为其中一些可能已受版权保护.
  • 我可以使用DiskLruCache存储位图,但找不到指导说明其工作原理的教程,并且在android开发人员网站上有关它的文章没有任何帮助.

也许滑行"是一种解决方案,但是我在需要时无法检索保存的位图.

Maybe `Glide is a solution but I could not retrieve the saved bitmap when I needed it.

是否有正确或最佳的方法?

Is there a correct or best way of doing it?

推荐答案

我不完全了解按用户下载图像,对其进行缓存但不允许以后显示的想法.

I don't fully understand the idea of downloading images by user, caching them but not allowing to display them later.

我认为您在这里有2个选择.

You have 2 options here in my opinion.

第一个是使用Glide缓存,但是您无法完全控制何时以及如何清除图像.

First one is to use Glide cache but you dont have full control of when and how images will be cleared.

第二个选项是将图像另存为files在私有目录中(用户将无法预览此图像),并在应用程序中创建某种逻辑(根据您的限制),以控制何时以及如何显示这些图像图片发送给应用中的用户.

Second option is to save images as files in private directory (user won't be able to preview this images) and create some kind of logic in application (based on your restrictions) to control when and how to display those images to users in app.

这篇关于如何缓存Firebase存储下载的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆