Skip to content

fix(cache): invalidate public profile cache after platform link mutations#530

Open
Ridanshi wants to merge 1 commit into
Dev-Card:mainfrom
Ridanshi:fix/public-profile-cache-invalidation
Open

fix(cache): invalidate public profile cache after platform link mutations#530
Ridanshi wants to merge 1 commit into
Dev-Card:mainfrom
Ridanshi:fix/public-profile-cache-invalidation

Conversation

@Ridanshi

@Ridanshi Ridanshi commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Closes #482

Summary

This PR fixes a cache consistency issue where public profile cache entries were not invalidated after platform link mutations.

Previously, creating, updating, deleting, or reordering platform links updated the database successfully but left stale public profile data in cache until TTL expiration.

Changes

  • Added public profile cache invalidation after successful platform link mutations
  • Centralized cache invalidation logic where applicable
  • Ensured invalidation only occurs after successful database operations
  • Preserved existing cache TTL behavior
  • Prevented stale platform link data from being served to visitors

Test Coverage

Added/updated tests covering:

  • Platform link creation invalidates cache
  • Platform link update invalidates cache
  • Platform link deletion invalidates cache
  • Platform link reorder invalidates cache
  • Cache repopulation after invalidation
  • Failed mutations do not invalidate cache
  • Consecutive mutations remain consistent

Result

Public profile data now stays consistent with platform link changes and visitors immediately see the latest profile state after mutations.

…ions

Root cause: createPlatformLink, updatePlatformLink, deletePlatformLink, and
reorderLinks all mutated the database but never called redis.del on the
profile:<username> cache key, leaving stale data served to viewers until
the 5-minute TTL expired naturally.

Fix: Add a private invalidateProfileCacheForUser helper that resolves the
username via a lightweight SELECT then calls redis.del. All four mutation
functions now await this helper after a successful DB write so the cache
is cleared immediately. Cache invalidation is skipped when Redis is absent
and errors are caught and logged non-fatally so a Redis blip never fails
a mutation request.

Also fix the DELETE /api/cards/:id route handler which checked error codes
as return values; the service throws errors, so the handler now catches them.
Fix cards.test.ts duplicate buildApp declaration, and apply the PlatformLink
type fix to cardService.ts (upstream/main has not yet merged that PR).

Tests: 21 new tests in profile-cache.test.ts cover cache hit/miss lifecycle,
all four mutation paths, failed mutations, non-existent links, Redis-absent
mode, consecutive mutations, cache repopulation, and non-fatal Redis errors.
@vercel

vercel Bot commented Jun 9, 2026

Copy link
Copy Markdown

@Ridanshi is attempting to deploy a commit to the Prashantkumar Khatri's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

Hi @Ridanshi,

Thanks for opening this pull request.

This PR has been automatically classified based on the files modified.

Applied Labels

  • backend

Primary Review Area

  • backend

Reviewer

@Harxhit has been identified as the primary reviewer for this pull request.

If you have any questions regarding the affected area or implementation details, feel free to reach out to the assigned reviewer.

Thank you for your contribution!

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

CI — Checks Failed

Backend — FAIL

Check Result
Lint FAIL
Test PASS
Typecheck PASS

Mobile — SKIP

Check Result
Lint -
Test -

Web — SKIP

Check Result
Check -
Build -

Last updated: Tue, 09 Jun 2026 19:51:26 GMT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Public profile cache is never invalidated after platform link mutations, causing stale DevCard profiles

1 participant