Local state and server cache: finding a balance
summary
Shows a concrete pattern for avoiding duplicated REST calls by using vue-query with Vue and Pinia plus axios: fetch list and item endpoints with useQuery(['characters'], fetch) and useQuery(['character', id], fetchById), supply placeholderData to avoid undefined states, set staleTime=5000ms to keep results cached, and disable default retries:3 and refetch-on-window-focus when undesired. Live demo proves cache prevents duplicate requests, supports select transforms, and notes mutations can update the cache though mutation code is not shown.
AI-written summary · about
