Persistence lifetime

前端 未结 3 932
执笔经年
执笔经年 2020-12-30 20:50

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

相关标签:
3条回答
  • 2020-12-30 21:22

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

    0 讨论(0)
  • 2020-12-30 21:34

    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.

    0 讨论(0)
  • 2020-12-30 21:45

    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.

    0 讨论(0)
提交回复
热议问题