electron - 电子索引数据库限制?
问题描述
在这个 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 特有的。
所以我的问题:
- 这正式改变了吗?
- 如果您尝试超过该限制(假设它不是真正的 100% 可用空间)会发生什么?
- Electron/Chromium 会驱逐你的数据吗?
--- 电子 v3.0.4
解决方案
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
推荐阅读
- javascript - 使用 Google 文档作为数据端点来获取 JSON
- javascript - 单击按钮时关闭电子窗口?
- python - Python 用 pyautogui 保存多张图片
- html - 导航栏中的下拉菜单不起作用
- python - python - 未解决的参考,我不知道为什么?
- c++ - 在布局 C++ QT 中移动小部件
- java - 使用 servlet 和 jquery 搜索数据库
- javascript - 从 getter 返回的函数的 `this` 关键字的值
- php - .htaccess 中的 Angular + Laravel PHP 路由
- sql - HIVE SQL:从庞大的数据库中仅选择一个值的最快方法是什么