ngrx-store-localstorage
ngrx-store-localstorage copied to clipboard
[Proposal] Add lifetime into the config
It's obvious that state saved in the local storage may become outdated.
Maximum lifetime for the cache in my application is 30 min. I would like to have an option to pull an actual state from server by certain timeout.
This would be a nice feature. In the meantime you can do it with a deserializer. I have something like this
export function popupDeserialize(popup: popupState.IPopupState) {
// Only rehydrate if popup was recently interacted with
const now = new Date();
const lastOpened = new Date(popup.lastOpened!);
const FIVE_MIN = 5 * 60 * 1000;
return now.getTime() - lastOpened.getTime() < FIVE_MIN
? popup
: popupState.initialState;
}
where lastOpened is the date the app was last interacted with.