"a vast majority of users do not actually need a normalized cache" ... "check with us first"
hello community, saw this warning in the docs and figured i'd ask if i'm in the rare minority on needing a normalized cache.
we have an SPA and a REST backend that returns JSON responses. the data is relational, and we have the option of having it nested, or making multiple requests for related entities. we have a websocket connection which gives updates in real time to individual entities. we show a large collection of entities and their related resources on the page (slightly expensive to fetch), and the realtime updates happen frequently and so, invalidating the cache upon receiving a websocket message would be wasteful compared to updating the cache in memory.
does anyone have any recommendations? my best idea has been to normalize the cache by spraying additional cache keys of each individual entity's primary key so that they can be updated easily, and then having to call getQueriesData in all of the components that need to read from the cache. i also saw someone made this library: https://github.com/klis87/normy/tree/master/packages/normy-react-query but i know that y'all have thought of nearly everything and still decided to put that warning in the docs
2 Replies
wise-whiteOP•2y ago
also would like to know if when i make a new query key for every individual record, does that have implications for memory? or would it be doing some pointer nonsense where the data being stored is just a reference?
extended-salmon•2y ago
Having a lot of subscribers to your cache might be a performance problem