fix: cache dashboard data with 2-minute TTL window (#84)#97
Merged
ayshadogo merged 2 commits intoJun 24, 2026
Conversation
Cache dashboard fetch results in Redux for 2 minutes so navigating away and back does not re-issue API calls.
- Add per-resource lastFetched timestamps in dashboardSlice
- Add 2-minute TTL cache condition to fetchDashboardStats/fetchRecentDonations/fetchRecentCampaigns
- Add invalidateDashboardCache action and force:{true} bypass arg
- Clear dashboard cache on logoutUser.fulfilled
- Wire Refresh button + central fetch in DashboardPage
- Invalidate campaigns / stats caches on CreateCampaign submit
- Fix duplicate import line in RecentCampaigns that broke lint
- Add cache-behavior tests with mocked api; 34/34 tests pass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Caches dashboard fetch results in Redux with a 2-minute TTL so the user can navigate away from the dashboard and back without triggering redundant API calls. A Refresh button bypasses the cache, and stale caches are invalidated when new campaigns are submitted.
Changes
lastFetchedtimestamps todashboardSlicestate.fetchDashboardStats,fetchRecentDonations, andfetchRecentCampaignswith a Redux Toolkitconditioncallback that skips the network request when data is fresh (withinDASHBOARD_CACHE_TTL_MS = 2 * 60 * 1000).{ force: true }arg on each thunk to bypass the cache (used by the Refresh button).invalidateDashboardCache(resource?)action; dispatchescampaigns+statsinvalidation after a successfulCreateCampaignPagesubmit.logoutUser.fulfilledin the dashboard slice so logging out clears cached data.DashboardPagethat fans out{ force: true }to all three thunks; centralize initial dispatch there as well.selectDashboardLastFetchedselector for inspecting cache state.import {syntax bug inRecentCampaigns.jsxthat was blocking lint.DashboardPage.test.jsxto register a stubdashboardreducer so the page renders under the existing test harness.dashboardThunks.test.jscovering: first-fetch, cache hit skipping, per-resource independence, force bypass, TTL expiry, invalidation of one/all resources, andclearDashboardreset.Testing
npm run lintpasses (0 errors; only pre-existing unrelated React Compiler warning inBasicInfoStep.jsx).npm run buildpasses.npm testpasses — 34/34 tests (10 from baseline + 24 from this change set; 9 new tests indashboardThunks.test.jsverify skip-on-fresh, force bypass, per-resource independence, TTL expiry, timestamps recorded on fulfilled, single-resource invalidation, all-resources invalidation, andclearDashboardreset).Closes #84