Skip to content

fix: cache dashboard data with 2-minute TTL window (#84)#97

Merged
ayshadogo merged 2 commits into
Dfunder:mainfrom
LaGodxy:fix/issue-84-dashboard-data-caching
Jun 24, 2026
Merged

fix: cache dashboard data with 2-minute TTL window (#84)#97
ayshadogo merged 2 commits into
Dfunder:mainfrom
LaGodxy:fix/issue-84-dashboard-data-caching

Conversation

@LaGodxy

@LaGodxy LaGodxy commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

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

  • Add per-resource lastFetched timestamps to dashboardSlice state.
  • Wrap fetchDashboardStats, fetchRecentDonations, and fetchRecentCampaigns with a Redux Toolkit condition callback that skips the network request when data is fresh (within DASHBOARD_CACHE_TTL_MS = 2 * 60 * 1000).
  • Support { force: true } arg on each thunk to bypass the cache (used by the Refresh button).
  • Add invalidateDashboardCache(resource?) action; dispatches campaigns + stats invalidation after a successful CreateCampaignPage submit.
  • Listen for logoutUser.fulfilled in the dashboard slice so logging out clears cached data.
  • Surface a Refresh button in DashboardPage that fans out { force: true } to all three thunks; centralize initial dispatch there as well.
  • Add selectDashboardLastFetched selector for inspecting cache state.
  • Fix pre-existing duplicate import { syntax bug in RecentCampaigns.jsx that was blocking lint.
  • Update DashboardPage.test.jsx to register a stub dashboard reducer so the page renders under the existing test harness.
  • Add dashboardThunks.test.js covering: first-fetch, cache hit skipping, per-resource independence, force bypass, TTL expiry, invalidation of one/all resources, and clearDashboard reset.

Testing

  • npm run lint passes (0 errors; only pre-existing unrelated React Compiler warning in BasicInfoStep.jsx).
  • npm run build passes.
  • npm test passes — 34/34 tests (10 from baseline + 24 from this change set; 9 new tests in dashboardThunks.test.js verify skip-on-fresh, force bypass, per-resource independence, TTL expiry, timestamps recorded on fulfilled, single-resource invalidation, all-resources invalidation, and clearDashboard reset).

Closes #84

LaGodxy and others added 2 commits June 24, 2026 06:38
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

@ayshadogo ayshadogo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Job Well Done

@ayshadogo ayshadogo merged commit 2c2ae58 into Dfunder:main Jun 24, 2026
2 checks passed
@grantfox-oss grantfox-oss Bot mentioned this pull request Jun 24, 2026
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dashboard Data Caching

2 participants