firebase / FirebaseUI-Android

Optimized UI components for Firebase
https://firebaseopensource.com/projects/firebase/firebaseui-android/
Apache License 2.0
4.61k stars 1.83k forks source link

Create a Firebase Storage caching class #993

Open samtstern opened 6 years ago

samtstern commented 6 years ago

I am filing this issue as a general feature request. I have already implemented this elsewhere, but would need some help from iOS to make it cross platform. In a number of my projects I have implemented a class with this signature:

interface FirebaseStorageFetcher {

   /**
    * Get a file from FirebaseStorage, or return the cached contents if the file has been downloaded
    * since the specified "max age"
    */
   public Task<byte[]> get(String path, long maxAge, TimeUnit timeUnit);

}

The class does a number of useful things:

One use case for this is storing a frequently accessed configuration file in Firebase Storage. This class encapsulates all of the logic needed to download it on a regular basis while treating it like a local file.

SUPERCILEX commented 6 years ago

Haha, I do exactly the same thing though I prefer to pass in a storage reference and return a file instead to the raw bytes for flexibility's sake.

samtstern commented 6 years ago

Yeah passing the StorageReference is definitely better (wonder why I chose String...). And the lib should offer a choice between bytes and File, since one of the nice thing about getting bytes is that it means you're done with operations that need to be done off the main thread.

SUPERCILEX commented 6 years ago

Oh true, we could just have the base method be the file one and add another method that's a continuation and reads the bytes using an async executor. Shouldn't be too hard, I like it. 😄

samtstern commented 6 years ago

Shower thought: this could eventually be expanded to handle uploads and downloads so that when you upload we populate the cache first. This would mean that you could use Firebase Storage in both directions offline. I'll have to ask the Storage folks if they'd considered this.

swftvsn commented 6 years ago

Hi, is there any news about this?

samtstern commented 6 years ago

@swftvsn no sorry we've been pretty consumed with the auth module and adding paging support to the firestore module these days ...

swftvsn commented 6 years ago

Thanks for the info and awesome lib! Can't wait to get the official paging support too :)

ShaMan123 commented 6 years ago

+1