localStorage and locking

2019-04-22 10:56发布

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?

3条回答
等我变得足够好
2楼-- · 2019-04-22 11:14

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.

查看更多
老娘就宠你
3楼-- · 2019-04-22 11:26

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).

查看更多
聊天终结者
4楼-- · 2019-04-22 11:30

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/

查看更多
登录 后发表回答