首页 > 解决方案 > 电子索引数据库限制?

问题描述

这个 Electron 问题中,@zcbenz 评论道:

我们与 Chrome 浏览器有相同的大小限制,即“可用磁盘空间的 1/3”。

这种回应是从 2016 年初开始的。

我已经运行了这段代码:

const estimation = await navigator.storage.estimate();
console.log(`Quota: ${estimation.quota}`);
console.log(`Usage: ${estimation.usage}`); 

它告诉我,我有 100% 的可用磁盘空间作为配额,所以我很困惑,找不到比 2016 年评论更新的东西,这也是 Electron 特有的。

所以我的问题:

--- 电子 v3.0.4

标签: electronindexeddb

解决方案


2019 年,我可以向您保证,您现在可以完全控制您的 indexdb 数据。
根据 Google 的这篇文章: https
://developers.google.com/web/updates/2017/08/estimating-available-storage-space 上面的代码应该返回正确的配额大小。
但除此之外,现在调用此代码会使您的数据无法被“驱逐”

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

https://developer.mozilla.org/en-US/docs/Web/API/StorageManager/persist


推荐阅读