IndexedDB& localStorage存储限制 [英] IndexedDB & localStorage Storage Limits

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

问题描述

根据我的理解,Chrome对localStorage和IndexedDB中存储的数据大小施加了5Mb的软限制。这里有很多事情我不清楚




  • 在这种情况下,软的含义是什么?
  • >
  • 这是否意味着localStorage:5Mb + IndexedDB:5Mb?

  • 我还没有打开缓冲区,但随后我开始清理我的浏览器商店应用程序。达到限制时会发生什么?抛出异常并需要被捕获?

  • 在存储之前压缩数据会有很多里程吗? 如果数据压缩是值得的话,这似乎提供了一条很好的路线。



压缩的代价是失去在IndexedDB中无缝存储/获取JSON的好处(尽管这可以变得透明给我的应用程序添加额外的功能)。



我非常感谢任何有关这些问题的指导。

解决方案

我写了一个小提琴来研究当软存储限制被破坏时会发生什么 - 还要测试压缩存储内容的效用。这里是小提琴



本地存储测试



我使用了压缩例程这里进行测试。实际压缩很容易完成

  var compr = LZString.compress(uncompr); 

笔记


  1. 测试需要一段时间才能执行,因此请耐心等待!
  2. 要增加存储数据的大小,只需增加maxTimes
  3. 压缩功能 - 非常好。但是,正如测试所证明的那样,它只能在存储相对较小(最多几个kb的顺序)字符串时真实地使用。对于较长的字符串,压缩本身需要很长时间,并且容易使您的应用程序无响应。我怀疑是否需要存储过长的字符串比压缩它们更好。

  4. 我使用这种技术将本地显示的HTML文档存储在localStorage中,并存储一系列配置数据对象在IndexedDB数据库中。

  5. 压缩存储在IndexedDB中的数据意味着您将无法存储/检索它提供的JS对象。然而,这可以通过一个简单的包装轻松解决。


From what I can understand Chrome imposes a "soft" limit of 5Mb on the size of data stored in localStorage and IndexedDB. There are a number of things here that are not clear to me

  • What precisely is meant by "soft" in this context?
  • Does this mean localStorage:5Mb + IndexedDB:5Mb?
  • I have not hit the buffers yet but then I keep clearing out my browser stores as I develop my app. What happens when the limits are reached? An exception is thrown and needs to be caught?
  • Would there be much mileage in compressing data prior to storage? This seems to offer an excellent route if data compression is worth doing.

Compression would come at the cost of loosing the benefits of being able seamlessly to store/fetch JSON in IndexedDB (though this can be made transparent to my app with little extra effort).

I'd much appreciate any guidelines with these issues.

解决方案

I wrote up a fiddle to examine what happens when the soft storage limits are breached - and also to test the utility of compressing what gets stored. Here is the fiddle

Local Storage Test

I have used the compression routines here for the test. The actual compression is easily done

var compr = LZString.compress(uncompr);

Notes

  1. The test need some time to execute so be patient!
  2. To increase the size of the stored data just increase maxTimes
  3. Compression works - very well indeed. However, as the tests will demonstrate, it can only realistically be used when storing relatively small (order of a few kb at the most) strings. For longer strings the compression itself takes too long and is liable to make your app unresponsive. I suspect that it would be better to question the need to store excessively long strings than to compress them.
  4. I use this technique for storing locally displayed HTML documents in localStorage and to store a range of configuration data objects in an IndexedDB database.
  5. Compressing data stored in IndexedDB means you loose the seamless storage/retrieval of JS objects that it offers. However, this can be dealt with easily via a simple wrapper.

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

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