If you work with local storage for caching data to client side, you feel to set expire date for data. This small library will help you to solve your problem.
npm i browser-caching
import { setLocalStorage, getLocalStorage } from "browser-caching";
setLocalStorage('flowgiri', 'flowgiri.com', 5)
This function has three parameters:
-
key
for storing data with the key -
value
Any type of data you need to store.
Note: No need to make stringify of array or object.
-
expireInMinute
(optional). You can pass minutes for caching data till the minutes. If you do not pass expire, data will store like defaultlocalStorage
.
This function will get your data as like as you store if expire is not over. If expire over then return null.