IndexedDB 的锁定模型?
IndexedDB 如何处理多个选项卡,每个选项卡都具有正在进行的异步事务?事务是否完全锁定所有相关的对象存储?我如何保证如果一个选项卡正在处理一段数据,则另一个选项卡不会做同样的事情?
How does IndexedDB handle multiple tabs each with asynchronous transactions in-flight? Do transactions lock all of the related object stores entirely? How can I guarantee that if one tab is working on a piece of data that another isn't doing the same thing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
IndexedDB 规范确定“如果多个 READ_WRITE 事务尝试访问同一对象存储(即,如果它们具有重叠范围),则首先创建的事务必须是首先访问对象存储的事务。由于要求在上一段中,这也意味着在事务完成之前它是唯一有权访问对象存储的事务。”
这意味着当事务处于 READ_WRITE 模式时,objectStore 将为其他 READ_WRITE 事务锁定,直到该事务完成。
您可以从这里阅读有关 IndexedDB 事务模式的更多信息 - http://www.w3.org/TR/IndexedDB /#dfn-mode
吉尔
The IndexedDB specifications determine that "If multiple READ_WRITE transactions are attempting to access the same object store (i.e. if they have overlapping scope), the transaction that was created first must be the transaction which gets access to the object store first. Due to the requirements in the previous paragraph, this also means that it is the only transaction which has access to the object store until the transaction is finished."
That means that when a transaction is in a READ_WRITE mode the objectStore will be locked for other READ_WRITE transactions up until the transaction will finish.
You can read more about the IndexedDB transaction modes from here - http://www.w3.org/TR/IndexedDB/#dfn-mode
Gil