简体   繁体   中英

Store temporary data (that automatically deletes after 1 minute) on Google Cloud Firestore

I have an application where users keep writing data to the database that only needs to last for 1 minute. For example, Alice stores {foo: bar} at 10:36:00pm, and at 10:37:00pm, that entry should automatically be deleted from the database to free up memory, as it will never be used again.

Is there a way to do this, or do I have no choice but to manually have users delete their temp data after a minute? That wouldn't be ideal, because if a user "forgets" to (eg they lose their internet connection or close the app before they delete), then that entry will stay taking up space forever unless I set up a worker manually cleaning the database of these old entries.

For the record, the intended use case is to have Firestore act as a WebRTC signalling server, where users temporarily signal each other to establish a p2p connection.

As far as I can tell, there's no such thing in Firestore . This mechanism is commonly described as TTL (Time To Live).

You can, however, roll your own TTL mechanism using Cloud Tasks .

For your use case, very “short-term”, heavy-rotation, ephemeral, and presumably small data, you may also consider Redis, which has built-in TTL and higher performance. Depending on your volume, may turn out cheaper as well.

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