FirebaseUI-Android icon indicating copy to clipboard operation
FirebaseUI-Android copied to clipboard

Create a Firebase Storage caching class

Open samtstern opened this issue 8 years ago • 8 comments

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:

  • Cache files locally, keeping track of last downloaded time
  • When asked for a file, it firsts issues a metadata request to see if the file has been recently updated

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.

samtstern avatar Oct 27 '17 17:10 samtstern

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.

SUPERCILEX avatar Oct 27 '17 18:10 SUPERCILEX

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.

samtstern avatar Oct 27 '17 18:10 samtstern

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. 😄

SUPERCILEX avatar Oct 27 '17 18:10 SUPERCILEX

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.

samtstern avatar Nov 10 '17 11:11 samtstern

Hi, is there any news about this?

swftvsn avatar Apr 18 '18 10:04 swftvsn

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

samtstern avatar Apr 18 '18 15:04 samtstern

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

swftvsn avatar Apr 19 '18 04:04 swftvsn

+1

ShaMan123 avatar Apr 23 '18 12:04 ShaMan123