3

I am working with React and have some data from the API that I must store/persist so that the API is not called every time the page is rendered, only the first time.

I was wondering what are the main differences between local, session and cache? What I saw was that localStorage is persisted in the browser forever until it is removed by the client, session storage is persisted until the user gets in to the new tab, but cache is an engima to me. If somebody could explain the difference between cache and the first two?

Also, I have a token that expires every 60 minutes and is checked on every API call. If it expires, the user is kicked out and must log on again to see the page. So, after 60 minutes of the user being logged in, I want to delete the persisted API data, kick the user -> user logs in again, call the API, fill the data...What is my best option? Cache, local, session, something else?

NoDiggityNoDoubt
  • 341
  • 1
  • 3
  • 18
  • Take a read of this, https://stackoverflow.com/questions/19867599/what-is-the-difference-between-localstorage-sessionstorage-session-and-cookies The last bit, the 'Cache' I think you mean is the browser cache, which is just when the browser caches things such as html pages, js files and images, and won't be relevant to what you're trying to achieve. – Michael Bauer Jul 18 '22 at 08:17
  • Does this answer your question? [localStorage vs sessionStorage vs cookies](https://stackoverflow.com/questions/29960037/localstorage-vs-sessionstorage-vs-cookies) – Gedeon Mutshipayi Jul 18 '22 at 08:18
  • Your idea about localStorage and sessionStorage is correct. Usually for maintaining app state, Redux is used in react. Have a look at Redux Toolkit. – alex87 Jul 18 '22 at 08:18

0 Answers0