Comments: A local cache mechanism is provided for us in html5. It will replace our cookies, and it will not be sent with the browser. Our server-side html5 cache mainly includes localStorage, and sessionStorage. For details, please refer to this article. In html5, we provide a local cache mechanism, which will replace our cookies and will not send our servers with the browser. We can use js to operate the local cache freely on the client. In html5, the cache mainly includes localStorage and sessionStorage. Their usage is consistent. The difference is that they have different time limits. LocalStorage does not have a time limit. In this case, session-based data storage will be deleted after the session is closed or the website is left.
Next, let's take a look at the official example operations.:
Javascript
The Code is as follows:
LocalStorage. fresh = "vfresh.org"; // set a key value
Var a = localStorage. fresh; // obtain the key value
Or use its API:
Javascript
The Code is as follows:
// Clear storage
LocalStorage. clear ();
// Set a key value
LocalStorage. setItem ("fresh", "vfresh.org ");
// Obtain a key value
LocalStorage. getItem ("fresh ");
// Return "vfresh.org" // obtain the name of the specified key (like Array)
LocalStorage. key (0 );
// Return "fresh" // delete a key value
LocalStorage. removeItem ("fresh ");
SessionStorage is the same, so you don't need to talk nonsense. It is equivalent to our cookie with the expiration time Expire = 0;