How to cache Firebase storage downloaded images

点点圈 提交于 2019-12-08 05:04:28

问题


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.

I need something like

FirebaseFirestoreSettings.setPersistenceEnables(true)

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

  • I tried saving the pictures to LruCache but all the cached data gets deleted once the app is closed.
  • I can save the pictures into a file and retrieve them but I don't want the user to have access to those pictures as some of them might be copyrighted.
  • I could store the Bitmaps using DiskLruCache but I cannot find a tutorial explaining how it works and the article about it on the android developer site is not of any help.

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?


回答1:


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

You have 2 options here in my opinion.

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

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.




回答2:


Try Picasso, it has an automatic image caching.



来源:https://stackoverflow.com/questions/54234883/how-to-cache-firebase-storage-downloaded-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!