Jonas
Jonas

Reputation: 7875

Firestore Offline: Make sure a specific Document is always cached

Lets say I have a workout app, where every workout is one DocumentSnapshot. I want to have a donwload button, that downloads a workout/document.

I'm already using firestore's offline capabilities, but I need to ensure, that when I have downloaded this document, it is always available when opening the app without a connection.

So is it possible to ensure, that a specific document is always being cached in the local firestore cache?

I could also just persist the data of the DocumentSnapshot, the problem with this is, I can't update the Document and have the changes being synchronized with the "online" database when reconnecting with the wifi.

Is there any good way to achieve this?

Upvotes: 1

Views: 63

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317372

So is it possible to ensure, that a specific document is always being cached in the local firestore cache?

It's not possible to ensure 100% of the time. The local cache is fully managed by the Firestore SDK. You don't have control over how it chooses to evict data from the cache. Any given cached document might be removed to make room for other documents in the future, if the cache becomes full.

Also, the cached document will not stay in sync with whatever is on the server, unless you write code to periodically query for (or listen for changes) in that document.

The functionality you're describing is best implemented with application code (probably with its own persistence layer) that specifically meets the needs of your app. The Firestore SDK won't do it for you.

Upvotes: 2

Related Questions