Need advice on caching data retrieved from useeffect in react
hey guys so im currently working on a project that will retrieve reddit posts and filter them by pain points similar to GummySearch but for a single niche to generate potential business ideas!
the reason im building this is cuz i cant pay $60 for gummy search 😦 and i thought it would be cool to build my own version to use for free for a single niche
anyways the problem is with the call to Reddit API now with useeffects in general the its called whenever the component mounts right but i dont want to do that. whats the best way to cache the posts retrieved from Reddits API on the client? i want to be refetching only after every 2 hours ! so say the user opens the app it fetches posts and then if the component unmounts and remounts i want to check if its been 2 hours since the last time, how can i do that check?? also where do i store the fetched posts? on local storage? do i save them to the database?
im currently not saving them to the database so im not sure whats the best method? if its not been 2 hours then i could fetch from the database ? if thats the case how would i model my relationships ? as i dont have a POST model yet in my Prisma PostgreSQL database
ill share my code for all relevant files
1 Reply
as u can see im not saving them to the database nor do i have a model for it
would appreciate some advice