localStorage存储大型数据 [英] localStorage store large size data

查看:200
本文介绍了localStorage存储大型数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据 http:// arty,我想使用localStorage存储大量数据(如800GB)。 name / localstorage.html 以及我使用的Firefox,我改变了我的localStorage大小和缓存大小。所以尺寸不是问题。但是,我写了一些jquery,如下:

I want to use localStorage to store large amount of data(like 800GB), according to http://arty.name/localstorage.html and also I'm using Firefox, I changed my localStorage size and also the cache size. So the size isn't a problem. However, I write some jquery like the following:

 $("a[href]").each(function(){
    $(this).click(function(event){
       localStorage.test += "somenewinformation";
      ...

如果这个localStorage.test已经有大量的数据,如400GB,所以存储信息的步骤会非常慢,当我点击一个链接,将jquery等待对我来说,完成添加新的信息到localStorage.test或者它只会去到下一页和localStorage.test中的信息将全部丢失或localStorage.test将保持旧的值?我不明白是一个新的线程

If this localStorage.test already have large amount of data like 400GB, so the storing information step would be extremely slow. When I click on a link,will the jquery wait for me to finish the appending new information to localStorage.test or it will just go to the next page and information in localStorage.test will all lost or localStorage.test will just remain the old value? What I dont understand is whether a new thread will be generated to do this storing in background or not and closing browser in the middle will affect it or not.

很抱歉,这些杂乱的描述和提前感谢!

Sorry about the messy description and thanks in advance!

推荐答案

您不能!通常限制为5 mb。

You can't! Usual limit is 5 mb.

浏览器如Opera允许你调整大小,但这完全依赖于浏览器,是一个用户发起的操作,而不是一个可编程的操作。

Some browser such as Opera allow you to adjust the size, but this is purely dependent on browser and is a user initiated action, not a programmable one.

即使你可以,请记住 localStorage 只能存储字符串,因此首先需要进行字符串化。与这是一个键/值存储数组,你会遇到性能很差的结束。

And even if you could, remember that localStorage can only store strings so anything else need to be stringified first. That together with this being an key/value storage array you will run into pretty poor performance at the end.

如果你需要大的存储容量,请查看File API。这是为了处理大文件(Blob),你可以存储任何东西作为一个Blob。

If you need large storage capacity, look into File API instead. This is made to work with large files (Blobs) and you can store anything as a Blob.

800 Gb是一个大型的文件API只能工作文件系统(最多可能比沙箱更慢,即不是纯文件系统)。

800 Gb is a large size and File API can only work as fast as the file system (at best, more likely a bit slower as it is sandboxed, ie. not a pure file system).

有关文件系统API的更多信息(注意:自2014年4月起停止):

http://www.w3.org/TR/file-system-api/

More about File System API (Note: discontinued as of 4/2014):
http://www.w3.org/TR/file-system-api/

教程:

http://www.html5rocks.com/en/tutorials/file/dndfiles/

Blob:

https://developer.mozilla.org/en-US/docs/Web/API/Blob

更新由于文件系统API已停止,因此除了将数据存储到服务器之外,基本上只剩下两个选项:

Update As the Filesystem API has been discontinued there are essentially only two options left (besides from storing data to the server):


  • 索引的数据库API aka 索引的数据库(推荐)

  • Web SQL as Safari)

  • Indexed Database API aka Indexed DB (recommended)
  • Web SQL (deprecated but still supported in browsers such as Safari)

此外,这些浏览器的大小最初还是有限的。

Also these are initially limited in size by the browser. It is possible to request a larger quote which the user is asked to accept.

在此处查看有关此API的更多详细信息:

http://www.w3.org/TR/IndexedDB/

See more details about this API here:
http://www.w3.org/TR/IndexedDB/

这篇关于localStorage存储大型数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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