Reputation: 3477
I am using IndexedDB as local storage and it is working well. For reasons that are too detailed to get into here, I often create just a single database and consume it, but in some instances I need to create more. In some of those cases, these additional databases may end up "orphaned" or unused, and unnecessary into the future. Do unused IndexedDB databases somehow "age out" of some sort of local storage cache (presumably in some browser-specific way)? I don't mind doing my own cleanup, but since there seems to be no definitive way to get a list of existing databases, I am unsure how to do it. And the ability of the user to merely delete ALL databases seems like a bit of a blunt instrument.....
I suppose I could keep a master-DB with a list of all existing databases.... but even then I don't think I can actually delete them. The best I could do is empty them I think.
Grateful for your insights.
Upvotes: 7
Views: 6660
Reputation: 981
I have website which can work offline, and while online You can download data for offline usage. Everything is stored in indexeddb. From user responses, data stays in it for years. But recently had report from user claiming his data are deleted by browser with no warning.
It turned out that when on android in chrome if drive(sd card) storage hit 80%, and browser try to store new data to indexeddb. Browser just delete everything in indexed db.
This is just me throwing some cents here, not really an answer.
Upvotes: 0
Reputation: 40038
According to this 2020 article, Safari will delete any IndexedDB database after 7 days of inactivity.
deleting all of a website’s script-writable storage after seven days of Safari use without user interaction on the site
Perhaps this is related to Apple's preference of App Store apps over unapproved PWAs.
https://webkit.org/blog/10218/full-third-party-cookie-blocking-and-more/
https://news.ycombinator.com/item?id=28158407
Upvotes: 1
Reputation: 49
if dont like that the browser delete the unused DBs under storage pressure, you can ask it to persist the storage
navigator.storage.persist()
that return a Promise
see: storage.persist definition and example
Upvotes: 1
Reputation: 9673
If you don't explicitly delete a database, generally it's going to stay there. But there are two scenarios where it will be deleted:
The user deletes it. For example, in Chrome if the user clears "cookies and site data", all IndexedDB databases will be removed.
The browser deletes it. Technically, the browser is allowed to delete any IndexedDB database at any time. In practice, this happens extremely rarely, possibly never. In theory it should happen when disk space is running low, but I've never seen it actually happen, even when I made an artificial test that used up all disk space in a VM.
What this means is that you can generally be pretty sure that an IndexedDB database is not going to be deleted unless you delete it, but you can't rely on that.
Upvotes: 9