7

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.

4 Answers 4

10

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:

  1. The user deletes it. For example, in Chrome if the user clears "cookies and site data", all IndexedDB databases will be removed.

  2. 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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks.... this leaves open (of course) the question of how to "play nice" with a computer that is low on disk space. No way for the client code to know anything about the space available on the disk, so no way to be more conservative in how much of a cache to implement in IndexedDB.... so it goes I guess.;
Stephan - Chrome has the quota API that you can use to know how much of your origin's quota allotment is left. But for now chrome distributes quota very conservatively; feel free to make the IDBs as big as you want without worrying about affecting the machine. developer.chrome.com/apps/offline_storage#query
1

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

2 Comments

the link is broken
Careful: This can't be un-done! I.e. there is no method like .unpersist() or something.
1

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

1 Comment

I had read the link, but i don't really understand how this works on installed (bookmarked to home screen) pwa. As it also says: "Web applications added to the home screen are not part of Safari and thus have their own counter of days of use."
0

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.