简体   繁体   English

我可以在浏览器ui线程和Web工作线程中安全地使用html5中的本地存储

[英]What local storage in html5 can I use safely in the browser ui thread and the web worker thread

I've been trying to use web sql database api in webkit based browsers. 我一直在尝试在基于webkit的浏览器中使用web sql数据库api I have been using the async api in the main ui thread and a web worker . 我一直在主ui线程web worker中使用async api 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. 似乎对底层sqlite数据库的访问不是线程安全的。

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. 我的Web工作者只是对一个表执行查询,该表可能从主ui线程中插入了一条记录。

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

Any insights would be gratefully received 任何见解都会感激不尽

You can't use localStorage or sessionStorage from WebWorkers. 您不能使用WebWorkers的localStorage或sessionStorage。

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/ 看看这个,它应该有所帮助: http//www.nczonline.net/blog/2012/04/25/the-performance-of-localstorage-revisited/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 HTML5 本地存储 - 我可以为每个键存储多个值,如果不能,我可以使用什么替代方法? - HTML5 local storage - Can i store more than one value per key, if not what alternative i can use? 在HTML5应用中将后台数据下载到浏览器数据库-settimeout与辅助线程 - Background data download in an HTML5 App to browser database - settimeout vs worker thread 你可以使用HTML5本地存储来存储文件吗?如果没有,怎么样? - Can you use HTML5 local storage to store a file? If not, how? 如何在Web Worker线程中使用javascript变量 - How to use javascript variable in Web worker thread 在HTML5中创建Web Worker时使用setTimeout() - Use of setTimeout() in creating web worker in html5 我可以使用本地存储创建非托管的HTML5应用吗? - Can I make a non hosted HTML5 app with local storage? 我可以在Angularjs承诺完成之前阻止浏览器UI线程吗? - Can I block browser UI thread until Angularjs promise finishes? 如何加密HTML5网络存储? - How can I encrypt HTML5 web storage? 我如何在PHP旁边使用HTML5本地存储,将其用于php会话,并存储php使用的其他信息 - How can i use HTML5 local storage along side PHP, use that for php sessions, and store other information that php uses 工人在Chrome中阻止UI线程 - Worker blocking UI thread in Chrome
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM