135. localStorage with expiration

medium  - accepted / - tried

localStorage is a simple and handy client-side storage, but you should avoid using it because it is synchronous.

Also Safari's ITP actually deletes client-side script-writable storage after 7 days of Safari use without interacting on your website, and localStorage is included.

Unlike Cookie, localStorage doesn't expire.

In this problem, please create a localStorage wrapper with expiration support

myLocalStorage.setItem('bfe', 'dev', 1000)
// 'dev'

after 1 second:

// null


localStorage is replaced with our own implementation to avoid security error. But the interface is the same, actually you don't need to care :)

Think aloud!