我可以在浏览器 ui 线程和 web 工作线程中安全地使用 html5 中的哪些本地存储
我一直在尝试在基于 webkit 的浏览器中使用 web sql 数据库 api 。我一直在主ui线程和网络工作者中使用异步API。两个线程都访问同一个数据库(正如您所知,这是 sqlite 的底层)
一切都表现良好,但偶尔事务会丢失或一个事务失败,这似乎是一种计时/竞争条件。看来对底层 sqlite 数据库的访问不是线程安全的。
多一点背景。我的网络工作者只是对一个表执行查询,该表可能有一条记录从主用户界面线程插入其中。
我想知道是否确实记录了可以从 ui 线程和网络工作线程安全访问的本地/网络存储?我在某处读到 indexeddb api 是线程安全的,但这对我现在没有帮助,因为对于我所针对的浏览器来说,浏览器对它的支持很差/不存在(至少我认为是这样) - 我从 http://caniuse.com 获取信息)
如有任何见解,我们将不胜感激
I've been trying to use web sql database api in webkit based browsers. I have been using the async api in the main ui thread and a web worker. Both threads access the same database (which as you know is sqlite underthehood)
Everything behaves fine but occassionally transactions are lost or one transaction fails and it seems to be a timing/race condition. It appears access to the underlying sqlite database is not thread-safe.
A bit more background. My web worker is simply executing a query against a table that may have a record inserted into it from the main ui thread.
I am wondering if it is actually documented somewhere what local/web storage can be accessed safely from both the ui thread and the web worker thread? I've read somewhere that the indexeddb api is thread safe but that does not help me right now since browser support for it is poor/non-existent for the browsers I am targeting (at least I think so - I get my information from http://caniuse.com )
Any insights would be gratefully received
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能使用 WebWorkers 中的 localStorage 或 sessionStorage。
虽然两者都是同步操作,但对于简单的数据写入和读取来说,它们并不是真正的问题。该问题在浏览器启动时更相关,但这是浏览器实现问题。
看看这个,它应该有帮助: http://www.nczonline.net/blog/2012/04/25/the-performance-of-localstorage-revisited/
You can't use localStorage or sessionStorage from WebWorkers.
While both are synchronous operations they aren't a real issue for simple data writing and reading. The issue is more relevant at browser start-up, but that's a browser implementation issue.
Take a look at this, it should help: http://www.nczonline.net/blog/2012/04/25/the-performance-of-localstorage-revisited/