google-chrome - 我或我的应用如何知道 Chrome 正在丢弃索引的数据库项目?

标签 google-chrome local-storage indexeddb

我有一个应用程序最近开始随机丢失 indexeddb 项目。我所说的“失去”是指他们被确认为已获救,但几天后,他们不再存在。

我的假设是 Chrome 正在丢弃 indexeddb 项目,因为磁盘已满。

我的问题是,我的应用程序是否可以监听任何事件,或者我可以引用任何 Chrome 日志条目以确认情况是否如此。注意。我不是要解决问题,我只是在寻找可以检测到它的方法。

最佳答案

Each application can query how much data is stored or how much more space is available for the app by calling queryUsageAndQuota() method of Quota API.See



您可以使用定期 BackgroundSync
估计分配给临时使用的已用空间和可用空间 using :
// index.html
navigator.serviceWorker.ready.then(registration => {
  registration.periodicSync.register('estimate-storage', {
    // Minimum interval at which the sync may fire.
    minInterval: 24 * 60 * 60 * 1000,
  });
});

// service_worker.js

self.addEventListener('periodicsync', event => {
  if (event.tag == 'estimate-storage') {
    event.waitUntil(estimateAndNotify());
  }
});

To estimate use the method: navigator.storage.estimate()//returns a Promise which resolves with {usage, quota} values in bytes. 

When TEMPORARY storage quota is exceeded, all the data (incl. AppCache, IndexedDB, WebSQL, File System API) stored for oldest used origin gets deleted.



您可以切换到无限制存储或持久存储。

关于google-chrome - 我或我的应用如何知道 Chrome 正在丢弃索引的数据库项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59501358/

相关文章:

javascript - 使用 JS 调整大小时的 Chrome 图标

javascript - 如何重置/删除 vuex 存储数据?

javascript - 如何从开发者工具中清除 IE10 & IE11 中的 localStorage?

sqlite - IndexedDB 性能和 IndexedDB 与 WebSQL 性能比较

html - 外部 css 在本地主机上工作正常但在远程服务器上不工作

jquery - 在 Chrome 中打印隐藏 DIV 中的图像失败

html - 网页在顶部显示空带

javascript - 为什么null在localStorage中存储为字符串?

indexeddb - IndexedDB 请求或事务在此时发送

javascript - IndexedDB 添加条目显示成功,但未显示在 chrome 开发工具中