feat: add caching layer with ISR and unstable_cache for improved performance#1441
Merged
danieltott merged 9 commits intomainfrom Dec 2, 2025
Merged
feat: add caching layer with ISR and unstable_cache for improved performance#1441danieltott merged 9 commits intomainfrom
danieltott merged 9 commits intomainfrom
Conversation
Add revalidate exports to enable Incremental Static Regeneration: - Homepage and events: 12 hours (43200s) - Podcast and members pages: 24 hours (86400s)
Wrap getEvents with unstable_cache for 12-hour caching with 'events' tag.
Wrap getSponsors with unstable_cache for 24-hour caching with 'sponsors' tag. Also fix null safety issue when sponsor.tier is null.
Wrap getEpisodes, getEpisode, and getTranscript with unstable_cache for 24-hour caching with 'podcast' tag.
Wrap getMembers with unstable_cache for 24-hour caching with 'members' tag.
Support revalidating by cache tag in addition to path: - /_cache?tag=events - invalidates events cache - /_cache?tag=sponsors - invalidates sponsors cache - /_cache?tag=podcast - invalidates podcast cache - /_cache?tag=members - invalidates members cache
👷 Deploy Preview for virtual-coffee-io processing.
|
danieltott
approved these changes
Dec 2, 2025
Member
danieltott
left a comment
There was a problem hiding this comment.
@JoeKarow this is great - thank you so much for getting this rolling!
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.
Linked Issue
N/A
Description
This PR implements a comprehensive caching strategy for the Virtual Coffee website using Next.js's Incremental Static Regeneration (ISR) and
unstable_cacheAPI to improve performance and reduce API calls.Changes Made:
1. ISR Configuration for Pages
revalidateexports to key pages:/) - revalidates every 12 hours/events) - revalidates every 12 hours/members) - revalidates every 24 hours/podcast,/podcast/[slug]) - revalidate every 24 hours2. Data Layer Caching with
unstable_cachesrc/data/events.ts: WrappedgetEventswith cache (12-hour TTL, tag:events)src/data/members/index.ts: WrappedgetMemberswith cache (24-hour TTL, tag:members)src/data/podcast.ts: WrappedgetEpisodes,getEpisode, andgetTranscriptwith cache (24-hour TTL, tag:podcast)src/data/sponsors.ts: WrappedgetSponsorswith cache (24-hour TTL, tag:sponsors)3. Enhanced Cache Revalidation Route
src/app/_cache/route.tsto support tag-based revalidation via?tag=query parameter/_cache?tag=eventsto revalidate all events-related cache)?path=parameter4. Bug Fix
sponsors.ts(sponsor.tier?.id) to prevent potential crashes when sponsor tier is nullFiles Modified (10 files):
src/app/%5Fcache/route.tssrc/app/events/page.tsxsrc/app/members/page.tsxsrc/app/page.tsxsrc/app/podcast/[slug]/page.tsxsrc/app/podcast/page.tsxsrc/data/events.tssrc/data/members/index.tssrc/data/podcast.tssrc/data/sponsors.tsMethodology
Why these changes?
Netlify Serverless Function Usage Spike: After upgrading from Next.js 15.0.0-rc to 15.5.4, Netlify Serverless Function usage dramatically increased. This is due to Next.js 15's change in default caching behavior—pages and data fetches are no longer cached by default, causing every request to trigger serverless function invocations.
Performance: CMS and external API calls (events, podcast, sponsors, members) are expensive operations. Caching reduces load times and API rate limiting concerns.
ISR + unstable_cache dual-layer approach:
unstable_cacheprovides data-level caching that works across different pages sharing the same dataTag-based revalidation: Enables surgical cache invalidation. When content is updated in the CMS, a webhook can call
/_cache?tag=podcastto invalidate only podcast-related caches without affecting other cached data.Cache duration rationale:
Code of Conduct