Some of the records of sessionStorage and localstorage

Initial contact to localstorage, too simple to understand the differences and the session

Is as follows: local: permanent storage, unless manually deleted or modified, based on the domain name, can store content around about 5m (write these words when opened detools found: the original is Jiang Zi!

session: non-permanent storage, only exist when the current tab is stored in sessionstorage, the current page will automatically shut down to clear the stored content

Floating on the surface is that these learned.

 

Recently met a demand, taking into account One solution is to use storage, originally used localstorage, setItem and removeItem have no problem, then I wanted to try sessionstorage, the question is

Reproduce what the situation is, click on a link to re-open a tab, the click event triggers the operation setItem, the purpose is to get in the newly opened tabs stored content to determine the components need to be rendered, because other times with no the content currently stored, so you want to get after it fell remove the content. When using localstorage, everything is carried out as expected, but sessionstorage has a problem, the problem lies in the operation of removeItem, session remove Remove only the lost memory content of the current tab, a jump to the page in front of it, session storage the content is still there, unless manually deleted or shut down the page, the data will always affect subsequent related operations.

According to my shallow knowledge and understanding, for localstorage, the stored key-value pair is more like a reference type data exist, as long as homologous tab, its operation will be performed by real-time feedback on each page

For sessionstorage, then open the operation of the new tab page homologous, more like a copy of the contents of a storage source tab, and in the face of any operation on this page will not do memory pages back to the source page, that is actually two sessionstorage are independent, the relationship just open a new tab, inherited already have a data only. Meditative side is written here seems really understand one of the characteristics sessionstorage: Clear the session data is stored at the end of the session.

In other words, if the browser opens multiple tabs homologous, when you close a tab, the other tabs or modify data stored should continue to exist, so follow close the current tab deleted, of course, data is only knowledge of the current page operated, that is, between session and local difference in addition to the above-mentioned literally outside, there is a deeper difference is that local data is homologous to safeguard a page, session data page is maintained independently of each respective data.

 

- Boundless Learning 

That the difference between these two things as literally as simple and clear, the results and found himself only just learned about a literal meaning of it

On page waiting for specific homologous to understand, the above mentioned circumstances do not include all homologous jump pages, in general, if you need to store data sharing chose localstorage store

 

Guess you like

Origin www.cnblogs.com/lesliecn/p/12105289.html