我或我的应用如何知道Chrome正在丢弃indexeddb项?

问题描述 投票:2回答:1

我有一个应用程序最近开始随机丢失indexeddb项目。 “丢失”是指确认它们已被保存,但几天后不再存在。

我的假设是,由于磁盘已满,Chrome正在丢弃indexeddb项。

我的问题特别是,是否有我的应用程序可以监听的任何事件,或者我可以参考的任何Chrome日志条目,以确认是这种情况。注意我不是要解决问题,而是要寻找可以检测到问题的方法。

google-chrome local-storage indexeddb
1个回答
0
投票

每个应用程序都可以查询存储了多少数据或更多数据通过调用queryUsageAndQuota()方法可为应用程序提供空间配额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. 

超过临时存储配额时,所有数据(包括存储最旧使用的AppCache,IndexedDB,WebSQL,文件系统API)原点被删除。

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

© www.soinside.com 2019 - 2024. All rights reserved.