I have been porting my old app from Redux to Zustand, and it's so much cleaner and nicer now.
However, I am hitting a few problems, and I am wondering what the best way forward is. I am making a podcast application, and the users visit a lot of podcasts. In the old app I would use localForage (also IndexedDB) to have a cache of podcasts, where each podcast had a key. When I wanted to read the podcast data I would read that cache, and after any changes save the cache again.
With Zustand I've tried to keep all those podcasts in a state.podcastCache object with their unique identifier as key. This seems to work very nicely. However I've recently started to get Out of Memory errors. This typically happens when I update the state often (even if no new content comes in) - eg. a simple change like updating state.podcastCache[uniquid].episodes[0].playedTime = currentTime;
So I am wondering a few options:
- Is Zustand keeping all of the state in memory, and this is what's leading to the problem? (I can see in my developer console that the state in IndexedDB is 25MB).
- Is 25MB too much for the state? I read online that IndexedDB can easily be several GB's, but I am unsure how large the state can realistically be before things start to go wrong.
- Is this the completely wrong way to handle data like this, and should I go back to have a more normal cache layer outside of Zustand?
Basically, any advice or suggestions to solve this problem is very very welcome.