Do I need to worry about managing the size of html5 localStorage, or will least recently used items be automatically removed?
Do I need to wor开发者_StackOverflow社区ry about managing the size of html5 localStorage, or will least recently used items be automatically removed?
The short answer
localStorage
will not expire.
The long answer
According to the currently published working draft, data should not expire. Specifically, I refer to the beginning of sections 4.2 and 4.3, where it says:
4.2 and 4.3:
User agents should expire data from the local storage areas only for security reasons or when requested to do so by the user. User agents should always avoid deleting data while a script that could access that data is running.Note that in 4.2, it goes on to describe that
sessionStorage
will be deleted when the browser has closed. But localStorage
should not expire because of time. In the editor's draft, it says sessionStorage
(only) may be deleted if the storage limit is encountered.
Of course, each storage space gets 5MiB (a fair bit for textual data), and there will be an exception thrown if you attempt to go over this limit. That makes handling the space requirements quite simple, as you can simply catch the exception and clear the data if need be.
精彩评论