我可以在浏览器ui线程和Web工作线程中安全地使用html5中的本地存储 [英] What local storage in html5 can I use safely in the browser ui thread and the web worker thread

查看:101
本文介绍了我可以在浏览器ui线程和Web工作线程中安全地使用html5中的本地存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试在基于webkit的浏览器中使用 web sql database api 。我一直在主 ui线程中使用 async api web worker 。两个线程都访问同一个数据库(正如你所知的那样是sqlite的继承)

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)

一切都表现得很好但偶尔交易丢失或一个交易失败而且它似乎是一个时机/竞争条件。似乎对底层sqlite数据库的访问不是线程安全的。

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.

多一点背景知识。我的Web工作者只是对一个表执行查询,该表可能从主ui线程中插入一条记录。

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.

我想知道它是否实际记录在某处可以从ui线程和Web工作线程安全地访问本地/网络存储吗?我已经读过某个地方 indexeddb api 是线程安全的,但这对我现在没有帮助,因为浏览器支持它对于我所针对的浏览器来说很差/不存在(至少我是这么认为的) - 我从 http://caniuse.com )获取我的信息

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 )

任何见解都会感激不尽

推荐答案

您不能使用WebWorkers的localStorage或sessionStorage。

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.

看看这个,它应该会有所帮助: http://www.nczonline.net/blog/2012/04/25 /再次访问本地存储的表现/

Take a look at this, it should help: http://www.nczonline.net/blog/2012/04/25/the-performance-of-localstorage-revisited/

这篇关于我可以在浏览器ui线程和Web工作线程中安全地使用html5中的本地存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆