IndexedDB & localStorage Storage Limits

一世执手 提交于 2019-12-11 11:29:15

问题


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.


回答1:


Here are the listed answers of your doubts:

  • Google Chrome has the quota of 5 MB. Here is the link to the specification - http://developer.chrome.com/extensions/storage.html#property-local-QUOTA_BYTES. Soft limit means it is the default quota, you can ask the user for his permission for more disk-space.
  • Quotas for localStorage are different from IndexedDB - here is the link for disk-space quota for IndexedDB - https://stackoverflow.com/a/20675480/867629
  • When the localStorage reaches 5MB Google Chrome produces an error in the javascript console log:

    Uncaught Error: QUOTA_EXCEEDED_ERR: DOM Exception 22
    

I haven't tried compression with locallStorage, so no idea about that.




回答2:


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.


来源:https://stackoverflow.com/questions/20756164/indexeddb-localstorage-storage-limits

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!