简体   繁体   中英

How do you delete queried data from firebase locally?

In my react native app, users are able to create and see posts (that can contain media) which are stored in Firebase's realtime database. It works correctly, however the size of the app increases greatly over time, which I assume is because more and more posts are queried and stored. Is this likely to be what causes the increased size of the app? If so, is it possible to delete such local data in the componentDidMount function?

There is no API to tell Firebase to clear its cache. But if you find that the size of the cache grows beyond what is reasonable for your app, you can explicitly set the cache size to something that works better for your users.

A few notes:

  • Storing images in the JSON database is in general not recommended, for many reasons. But one of them is precisely because those image would disproportionally affect the cache size. Consider storing the images in a dedicated file storage solution, like Cloud Storage for Firebase, and using a image-caching library.
  • Firebase's local persistence functions as a cache. You should not treat Firebase as a purely local database, as its local performance will deteriorate over time as the cache grows. If your clients never connect to the Firebase servers, you might want to consider using another database, which is optimized for pure local usage.

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