简体   繁体   中英

Reserve space in IndexedDB

I'm writing a diagnostics application that writes data to IndexedDB every three seconds. The size of the data is fixed and data older than one week is automatically deleted, resulting in max 201600 entries. This makes calculating the IndexedDB space requirements rather easy and precise. I would like to reserve space in IndexedDB when the site is launched, as the end user is likely to leave the browser unattended for large periods of time.

The simple solution seems to be to store a very large object that will prompt the user to accept space requirements. This requires storing then deleting a very large object, which takes a lot of time and processing power. This would also require checking whether this test has already taken place to ensure that it is only run once.

Is there a better solution?

I don't think there is a good solution to this. Even your solution doesn't really work. Just because you were once able to store a certain amount of data doesn't mean you will always be able to store that amount of data. The quota isn't constant. For instance, in Chrome it's roughly 10% of free hard drive space , which clearly can change over time.

If possible, the best solution would be to make your app gracefully handle the case where the quota is exceeded. Because it will happen no matter how you design your app.

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