简体   繁体   中英

Does Firestore ever purge its own document cache?

Assume every time an app launches, a listener is attached to a certain document in Firestore. Is it safe to assume that this document will always be available in the cache should the app ever go offline given that a listener is always attached to it? Does Firestore cache some documents with higher priority like this one because they are always accessed? And does Firestore ever purge this cache behind the scenes?

I ask because I have the option to backup this data to disk on the client but wonder if it's even necessary—when would this backup ever really be used?

Documents do not stay in cache forever. The cache has a maximum size, and if a new document in cache would cause that limit to be exceeded, old documents will be evicted from cache. The cache could also be purged by the user if they clear the app's data. According to the documentation :

When persistence is enabled, Cloud Firestore caches every document received from the backend for offline access. Cloud Firestore sets a default threshold for cache size. After exceeding the default, Cloud Firestore periodically attempts to clean up older, unused documents. You can configure a different cache size threshold or disable the clean-up process completely.

If you must have a document available locally at all times, you should implement your own persistent storage to get that guarantee.

To read more about how the cache works, read this post .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM