本地存储和锁定
由于 (html5) localStorage 及其等效项在选项卡和窗口之间持续存在,因此我考虑过使用它来传递消息。问题是获取和存储是不同的操作,因此不是原子的。我的模型依赖于 UUID 生成、冲突解决和信标来完成我需要做的一小部分工作,但我真正的问题是:
由于本地存储是共享内存资源,因此可用的锁定机制是什么?相互访问?
Since (html5) localStorage and its equivalencies persist in between tabs and windows, I've thought about using it for message passing. The problem is that fetch and store are different operations, and therefore not atomic. I have models that rely on UUID generation, conflict resolutions, and beaconing to do the small subset of what I need to do, but my real question is this:
Since the local storage is a shared memory resource, what are the locking mechanisms available for mutual access?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Benjamin Dumke-von der Ehe 最近提出了一些 localStorage 的(实验性)锁定代码: http://balpha.de/2012/03/javascript-concurrency-and-locking-the-html5-localstorage/
更新:代码链接文章中的内容已损坏,但 Github 上 是代码,特别提到了该文章。
Benjamin Dumke-von der Ehe recently came up with some (experimental) locking code for localStorage: http://balpha.de/2012/03/javascript-concurrency-and-locking-the-html5-localstorage/
Update: the code link in the article is broken, but here on Github is code, specifically mentioning the article.
我认为您真正需要的是 频道消息传递,尽管据我所知还没有人实现它。它允许脚本之间任意客户端消息传递。
I think what you really need is Channel Messaging, though as far as I'm aware no-one has implemented it yet. It allows arbitrary client side messaging between scripts.
没有任何内置的。您必须想出自己的锁定机制。当然,您可以使用其他人为其他事情提出的任何现有方法(例如锁定内存缓存)。
There aren't any built-in. You'll have to come up with your own locking mechanism. You can off course use any of the existing methods that other people have come up with for other things (like locking in memcache for instance).