Create a Firebase Storage caching class
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.
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.
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.
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. 😄
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.
Hi, is there any news about this?
@swftvsn no sorry we've been pretty consumed with the auth module and adding paging support to the firestore module these days ...
Thanks for the info and awesome lib! Can't wait to get the official paging support too :)
+1