假设我打电话给本地存储,如下所示:
window.localStorage.setItem("key", bigJsonObject);
window.localStorage.getItem("key")
bigJsonObject会被部分写入吗?或者整个写入会失败吗?他们有什么方法可以保证不会有部分写入?
解决方法:
参见§4.1 of the “web storage” specification:
The
setItem()
andremoveItem()
methods must be atomic with respect to failure. In the case of failure, the method does nothing. That is, changes to the data storage area must either be successful, or the data storage area must not be changed at all.
但是,(历史上)在这方面存在浏览器错误,e.g. some time before Chrome 21 until some time before Chrome 29.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。