Zha*_* Yi 4 javascript google-chrome indexeddb pouchdb
我使用pouchDB与IndexedDB在Chrome浏览器适配器和我要计算每个IndexedDB的数据库大小。我使用https://github.com/jonnysmith1981/getIndexedDbSize/blob/master/getIndexedDbSize.js 中的代码进行计算。
我发现数据库的总大小远远大于 webkit 临时存储的使用量。
下面的屏幕截图是我的应用程序使用的总存储空间 (255MB)。
你会看到有 5 个数据库保存在IndexedDB. 下面输出的是每个数据库大小的计算结果。您将看到总大小约为 389MB。我想知道为什么它们完全不同。哪一个是正确的?
--------- _pouch_products -------------
VM1633:51 - attach-seq-store : 0 B
VM1633:51 - attach-store : 0 B
VM1633:51 - by-sequence : 86.7 MB
VM1633:51 - detect-blob-support : 2 B
VM1633:51 - document-store : 92.3 MB
VM1633:51 - local-store : 6.1 KB
VM1633:51 - meta-store : 96 B
VM1633:57 TOTAL: 179.0 MB
--------- _pouch_transactions -------------
VM1633:51 - attach-seq-store : 0 B
VM1633:51 - attach-store : 0 B
VM1633:51 - by-sequence : 13.7 KB
VM1633:51 - detect-blob-support : 2 B
VM1633:51 - document-store : 2.2 KB
VM1633:51 - local-store : 4.2 KB
VM1633:51 - meta-store : 96 B
VM1633:57 TOTAL: 20.2 KB
--------- _pouch_products-mrview-4c294f20854f412a71c9e7cf2f9cc58f -------------
VM1633:51 - attach-seq-store : 0 B
VM1633:51 - attach-store : 0 B
VM1633:51 - by-sequence : 11.9 MB
VM1633:51 - detect-blob-support : 0 B
VM1633:51 - document-store : 35.3 MB
VM1633:51 - local-store : 15.1 MB
VM1633:51 - meta-store : 136 B
VM1633:57 TOTAL: 62.3 MB
--------- _pouch_products-mrview-fdca57d512425c6ed0f20311a4f8d6d1 -------------
VM1633:51 - attach-seq-store : 0 B
VM1633:51 - attach-store : 0 B
VM1633:51 - by-sequence : 86.2 MB
VM1633:51 - detect-blob-support : 0 B
VM1633:51 - document-store : 44.2 MB
VM1633:51 - local-store : 17.4 MB
VM1633:51 - meta-store : 136 B
VM1633:57 TOTAL: 147.7 MB
--------- _product_alerts -------------
VM1633:57 TOTAL: 0 B
Run Code Online (Sandbox Code Playgroud)
Indexed DB API 不提供查询数据库(或存储/索引)大小的方法。将键和值转换为字节也是浏览器执行的操作,脚本不可见。因此,脚本必须进行近似处理,例如,当序列化为字符串时,计算存储中所有键和值的大小。
Chrome 中的索引数据库实现使用名为 leveldb 的后备存储,它具有各种大小优化,例如使用另一个名为“snappy”的库进行键前缀压缩和值压缩。字符串也可以通过多种方式序列化为字节(例如,JS 字符串是每个字符 16 位,可以天真地存储为每个字符 2 个字节或编码为每个字符 1-4 个字节的 UTF-8)。当数据被删除或覆盖时,后备存储也会懒惰地压缩,因此它最终可能会占用比临时需要更多的空间。
这些优化也对脚本不可见,并且所有优化都会因浏览器而异,因此近似值将是...近似值。鉴于所有这些,估计 389MB 与浏览器报告的 255MB 相当不错!
在 Chrome 中,我们正在试验通过navigator.storage.estimate()API报告的按类型细分,该细分将为每种存储类型(例如,索引数据库与缓存与...)提供确切的值,尽管它仍然不会给出每个数据库或每个对象存储值。
| 归档时间: |
|
| 查看次数: |
1613 次 |
| 最近记录: |