In my project I use Firebase Realtime database and Firebase Storage. Results from the database get cache but the information from Firebase Storage does not. I'd like to create a cache system that is compatible with the realtime database such that parts of the database that are references to files held in Firebase Storage would create a cached file from the url the database reference contains. How would I go about doing that exactly?

- 130,605
- 17
- 163
- 193

- 929
- 1
- 7
- 19
-
What are you using to show the content in storage? I assume those are images & you are coding with Java? Have you looked at image loading libs like Picasso or Glude? They usually have some caching mechanism built in – TheBen Apr 26 '18 at 23:12
-
Sorry for not mentioning it earlier, but I'm storing videos and playing them with exoplayer. My attempts of trying to cache with exoplayer were futile. @TheeBen – Joel Robinson-Johnson Apr 27 '18 at 18:28
-
No problem, I highly recommend you find another option for videos. Firebase storage is not suitable for videos. Even the Firebase team have mentioned this https://stackoverflow.com/a/37870706/5601401. Also I meant Glide in my last comment not Glude. – TheBen Apr 27 '18 at 19:01
1 Answers
The Firebase SDKs for Cloud Storage don't natively support offline access. But I definitely recommend to use a library named Glide for Android to download and display images. You will have offline disk cache support, but that is not apart of the core Android SDK for Cloud Storage.
So using Glide
you'll never have to worry about implementing any sort of memory or disk cache. You can expect that if an image has already been loaded by Glide, and it has not been evicted from both memory of disk caches, that it will be immediately available while offline without adding any additional code.
You also can configure the sizes of the caches. Here's what the documentation has to say about the default disk cache size:
The internal cache factory places the disk cache in your application's internal cache directory and sets a maximum size of 250MB.
And for the memory cache:
Default sizes are determined by the MemorySizeCalculator class. The MemorySizeCalculator class takes into account the screen size available memory of a given device to come up with reasonable default sizes.

- 130,605
- 17
- 163
- 193