WebStorage
约 2 分钟阅读
- web.dev/storage-for-the-web
- chromium storage/browser/quota/quota_settings.cc
- Test of localStorage limits/quota
- mdn
- Storage API
- StorageManager
- 估算使用量
- AsyncStorage - React Native
存储限制
| name | limit |
|---|---|
| sessionStorage | 5 MB |
| localStorage | 5 MB |
| Cookie | 4 KB |
| Cookie kv | 1 KB |
| IndexedDB | 10 MB - 2GB |
- 不同浏览器限制不同,这里列举 安全/常见值
- IndexedDB
- 持久数据
- 数据量大
- 跨 Tab
- Worker 支持
- 插入性能弱 - 官方以优化读取性能为主
- 参考
- Why IndexedDB is slow
- 考虑 relaxed 持久化 - durability
- 可以 in-memory 读,write back 到 indexeddb
- Storing images and files in IndexedDB
- 存储为 Blob
- Why IndexedDB is slow
- sessionStorage
- 持久
- 小数据
- KV
- 可 Observe
- 跨 Tab
- localStorage
- 临时存储
- 敏感信息
- 可跨 Tab 感知变化
- Cookie
- 网络通讯 credentials
- CacheStorage
- Response stored in a Cache won't contain headers
- The Cache API: A quick guide
- stale-while-revalidate
Performance
| store | 10000 |
|---|---|
| localStorage | 110ms |
| IndexedDB | 1500-2200ms |
IndexedDB 很慢
Library
- dexie笔记dexiedexie/Dexie.js · Apache-2.0, JS, TS · A Minimalistic Wrapper for IndexedDB · dexie-react-hooks · useLiveQuery>) · 会 observe 数据变化打开:/notes/web/script/lib/dexie
- IndexedDB 存储
- 支持同步 - 但不是开箱即用
- ~82kB/26kB - 无依赖
- rxdbGitHubpubkey/rxdbrxdb · Apache-2.0, Typescript · offline first · 有 schema · 支持 punchdb, lokijs, dexie 存储 · 默认支持 REST 和 GraphQL 同步 · 使用 punchdb 也可以用 CouchDB 的同步笔记:RxDB
- Apache-2.0, Typescript
- offline first
- 有 schema
- 支持 punchdb, lokijs, dexie 存储
- 默认支持 REST 和 GraphQL 同步
- 使用 punchdb 也可以用 CouchDB 的同步
- Premium: IndexedDB, SQLite, Sharding, Query Optimizer
- ~114kB/31kB
- binary-decision-diagram
- broadcast-channel
- event-reduce-js
- spark-md5
- object-path
- clone
- rxdb.info/nodejs-database.html
- clientdb/clientdbGitHubclientdb/clientdb
- Apache-2.0, Typescript
- in-memory database, realtime
- PouchDB
- CouchDB replication
- 支持 attachments
- ~117kB/37kB
- uuid
- spark-md5
- techfort/LokiJSGitHubtechfort/LokiJS
- in-memory database
- YousefED/SyncedStoreGitHubYousefED/SyncedStore
- 基于 yjs 同步
- 构建协作应用
- localForge
- 类似 localStorage
- 异步
- 支持多后端
- Nozbe/WatermelonDBGitHubNozbe/WatermelonDB
- 定位是 DB - 使用 class+decorator 定义 模型
- React - LokiJS
- React Native - SQLite
- ~155kB - 基于 rxjs
- Absurd-SQL
- indexeddb
- SQLite
- empscripten Filesystem API
- DuckDB WASM
- Supabase
- RethinkDB
- Horizon
- NeDB
- Node.js, nw.js, Electron, Browser
- MongoDB 查询语法
- 项目停止
- amark/gunGitHubamark/gunamark/gun · http://gun.js.org/ · 实时 · 分布式 - 点对点 · 离线优先 · 图 · CRDT · 相关技术 · AXE - Advanced eXchange Equation · P2P 网络层 · DAM - Daisy-chain Ad-hoc Mesh-network笔记:GunDB
- syncing decentralized graph data
- isaacs/node-lru-cacheGitHubisaacs/node-lru-cache
- typicode/lowdbGitHubtypicode/lowdb
- MIT, JS
- Simple and fast JSON database
- 支持 nodejs、browser、memory
- FrigadeHQ/remote-storageGitHubFrigadeHQ/remote-storage
- 非常简单的 remoteStorage 实现
- GET/PUT/DELETE
https://api.remote.storage/entities/{key} - Header
- x-remote-storage-instance-id
- x-remote-storage-user-id
关联信息
反向链接、本文链接的其他页面和外部资料。
站内链接
- dexie笔记 · dexie
dexie/Dexie.js · Apache-2.0, JS, TS · A Minimalistic Wrapper for IndexedDB · dexie-react-hooks · useLiveQuery>) · 会 observe 数据变化
References
GitHub9 条
- amark/gungithub.com/amark/gun
- clientdb/clientdbgithub.com/clientdb/clientdb
- FrigadeHQ/remote-storagegithub.com/FrigadeHQ/remote-storage
- isaacs/node-lru-cachegithub.com/isaacs/node-lru-cache
- Nozbe/WatermelonDBgithub.com/Nozbe/WatermelonDB
- pubkey/rxdbgithub.com/pubkey/rxdb
- techfort/LokiJSgithub.com/techfort/LokiJS
- typicode/lowdbgithub.com/typicode/lowdb
- YousefED/SyncedStoregithub.com/YousefED/SyncedStore
其他外链15 条
- rxdb.info/slow-indexeddb.htmlrxdb.info/slow-indexeddb.html
- arty.name/localstorage.htmlarty.name/localstorage.html
- chromium.googlesource.com/chromium/src/+/refs/heads/main/storage/browser/quota/quota_settings.ccchromium.googlesource.com/chromium/src/+/refs/heads/main/storage/browser/quota/quota_settings.cc
- developer.mozilla.org/en-US/docs/Web/API/Cachedeveloper.mozilla.org/en-US/docs/Web/API/Cache
- developer.mozilla.org/en-US/docs/Web/API/IDBTransaction/durabilitydeveloper.mozilla.org/en-US/docs/Web/API/IDBTransaction/durability
- developer.mozilla.org/en-US/docs/Web/API/Storage_APIdeveloper.mozilla.org/en-US/docs/Web/API/Storage_API
- developer.mozilla.org/en-US/docs/Web/API/StorageManagerdeveloper.mozilla.org/en-US/docs/Web/API/StorageManager
- hacks.mozilla.org/2012/02/storing-images-and-files-in-indexeddbhacks.mozilla.org/2012/02/storing-images-and-files-in-indexeddb
- nolanlawson.github.io/database-comparisonnolanlawson.github.io/database-comparison
- pubkey.github.io/client-side-databases/database-comparison/index.htmlpubkey.github.io/client-side-databases/database-comparison/index.html
- reactnative.dev/docs/asyncstoragereactnative.dev/docs/asyncstorage
- rxdb.info/nodejs-database.htmlrxdb.info/nodejs-database.html
- web.dev/cache-api-quick-guideweb.dev/cache-api-quick-guide
- web.dev/storage-for-the-webweb.dev/storage-for-the-web
- www.mnot.net/blog/2007/12/12/stalewww.mnot.net/blog/2007/12/12/stale