Persistence lifetime
Asked Answered
O

4

41

I read few articles about IndexdDB, but couldn't find details about the lifetime of persisted data. I plan to use it for a session of data manipulation and upload once the user finishes. But what will happen if:

  • user close the browser tab
  • user closes the browser
  • user restarted the system

Also, I maintain user session through cookie based authentication. What will happen if the user logs off and log back in again? Is there a way to retrieve the data before the logoff?

Any documentation on handling this is appreciated. I skimmed through the spec, but it is not that good a read.

Thanks.

Oyster answered 4/4, 2013 at 16:33 Comment(0)
R
22

It's like localStorage, so it's cross-session, meaning restarting browser or system won't affect what is stored in it. However, user can clear it like clearing cookie. So it's just like persistent cookie, you don't trust it from the server-side, and you always need to check its integrity.

Rabbinism answered 4/4, 2013 at 18:43 Comment(0)
G
15

Persistent Storage has been available in Chrome since v52 and Firefox since v55. Support in other browsers can't be relied on though. You must test if persistent storage is available and react accordingly.

if (navigator.storage && navigator.storage.persist) {
  navigator.storage.persist().then(persistent => {
    if (persistent) {
      console.log("Storage will not be cleared except by explicit user action");
    } else {
      console.warn("Storage may be cleared by the UA under storage pressure.");
    }
  });
}

Chrome requires permission to use this feature. It will automatically be granted when calling navigator.storage.persist() if any of the following are true:

  • The site is bookmarked (and the user has 5 or less bookmarks)
  • The site has high site engagement
  • The site has been added to home screen on mobile device
  • The site has push notifications enabled

This list comes from an article outlining Chrome's implementation which is updated periodically with new information about this subject.

Gorgoneion answered 28/3, 2019 at 17:16 Comment(1)
In the current chrome version, the permission is granted forever, even if you remove the bookmark.Gristly
L
6

As of 2022, IndexedDB is persistent type of data storage. Thus, it is evicted if the user chooses to.

Note: After introducing Storage API, the "permanent" folder can be considered obsolete; the "permanent" folder only stores IndexedDB persistent-type databases. It doesn't matter if box mode is "best-effort" or "persistent" — data is stored under /storage/default. https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Browser_storage_limits_and_eviction_criteria

So, If user logs off and log back in again, then user can access data as before logs off.

Lip answered 10/8, 2022 at 4:58 Comment(2)
The data can also be removed without the intervention of the user if the browser runs out of space in the hard drive, as explained in your MDN link.Channa
it is 2023 and mobile chrome removing me indexeddb how it likes it - no setting I see to set it permanent -- ios safari is permanentDisinter
S
5

IndexedDB data belong to a type of temporary. So these data can be wiped out at any time.

These data size/lifetime are managed by very new Quota Management API.

In the future, IndexedDB could possibly used persistance type (not likely and not good idea too).

Soapy answered 5/4, 2013 at 2:44 Comment(2)
so how to get guarantee of permanent storage? for instance local cache of large database which is expensive to keep having to copy to the device?Underdog
It appears that Chrome is moving forward with allowing for persistence to be turned on. But it doesn't look like it will be generally available until October 2016. developers.google.com/web/updates/2016/06/persistent-storageTeratogenic

© 2022 - 2024 — McMap. All rights reserved.