ngrx-store-localstorage icon indicating copy to clipboard operation
ngrx-store-localstorage copied to clipboard

[Proposal] Add lifetime into the config

Open cwayfinder opened this issue 7 years ago • 1 comments

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.

cwayfinder avatar Feb 28 '18 14:02 cwayfinder

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.

bufke avatar Jul 06 '18 13:07 bufke