I need help on how to clear an Item or localStorage after a certain time even if the website is not currently working. More like a timeout when the localStorage should be cleared. Thank you
I need help on how to clear an Item or localStorage after a certain time even if the website is not currently working. More like a timeout when the localStorage should be cleared. Thank you
Share Improve this question asked Aug 2, 2018 at 15:31 Bello MayowaBello Mayowa 551 gold badge2 silver badges7 bronze badges 1- 1 There is no localStorage expiry mechanism, but you could create your own by e.g. storing a timestamp in localStorage and on each page load check if it has expired, or create a timeout for when you will manually remove it. – Tholle Commented Aug 2, 2018 at 15:37
1 Answer
Reset to default 6localStorage does not have support for expiration dates.
You can although save in localStorage a timestamp and next time the app starts up, check the timestamp and if it is too old than clean your app's localStorage.
Another way, if you want to set an expiration date on something, you can try with Cookies
There are some packages that help with this like js-cookie