我有一个应用程序最近开始随机丢失 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/