Skip to content

Commit ecd1cae

Browse files
JoeKarowdanieltott
andauthored
feat: add caching layer with ISR and unstable_cache for improved performance (#1441)
* feat: add ISR configuration to page files Add revalidate exports to enable Incremental Static Regeneration: - Homepage and events: 12 hours (43200s) - Podcast and members pages: 24 hours (86400s) * feat: add unstable_cache to events data fetching Wrap getEvents with unstable_cache for 12-hour caching with 'events' tag. * feat: add unstable_cache to sponsors data fetching Wrap getSponsors with unstable_cache for 24-hour caching with 'sponsors' tag. Also fix null safety issue when sponsor.tier is null. * feat: add unstable_cache to podcast data fetching Wrap getEpisodes, getEpisode, and getTranscript with unstable_cache for 24-hour caching with 'podcast' tag. * feat: add unstable_cache to members data fetching Wrap getMembers with unstable_cache for 24-hour caching with 'members' tag. * feat: add tag-based revalidation to cache route 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 * Add path type parameter * update type * add revalidate to a few more --------- Co-authored-by: Dan Ott <[email protected]>
1 parent 2d0b4f0 commit ecd1cae

File tree

14 files changed

+107
-12
lines changed

14 files changed

+107
-12
lines changed

src/app/%5Fcache/route.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,29 @@
11
import { type NextRequest } from 'next/server';
2-
import { revalidatePath } from 'next/cache';
2+
import { revalidatePath, revalidateTag } from 'next/cache';
33
import { redirect } from 'next/navigation';
44

55
export const dynamic = 'force-dynamic';
66

77
export async function GET(request: NextRequest) {
88
const searchParams = request.nextUrl.searchParams;
9-
const queryparam = searchParams.get('path');
10-
let path = typeof queryparam === 'string' ? queryparam : '/';
9+
const tagParam = searchParams.get('tag');
10+
const pathParam = searchParams.get('path');
11+
const pathTypeParam = searchParams.get('pathType');
12+
13+
// Handle tag-based revalidation if provided
14+
if (tagParam) {
15+
revalidateTag(tagParam);
16+
}
17+
18+
// Handle path-based revalidation if provided
19+
let path = typeof pathParam === 'string' ? pathParam : '/';
1120
if (!path.startsWith('/')) {
1221
path = '/' + path;
1322
}
1423

15-
// Invalidate the /posts route in the cache
16-
revalidatePath(path);
24+
if (pathParam) {
25+
revalidatePath(path, pathTypeParam === 'layout' ? 'layout' : 'page');
26+
}
1727

1828
redirect(path);
1929
}

src/app/(simple-mdx)/[...slug]/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { MDXProps } from 'mdx/types';
99
import { Metadata } from 'next';
1010
import { notFound } from 'next/navigation';
1111

12+
// ISR: Revalidate every 24 hours
13+
export const revalidate = 86400;
14+
1215
export function generateStaticParams() {
1316
const allFiles = loadMdxDirectory({
1417
baseDirectory: 'content/simple-mdx-pages',

src/app/events/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import { Google } from '@/svg/calendar/Google';
99
import { Outlook } from '@/svg/calendar/Outlook';
1010
import { Ics } from '@/svg/calendar/Ics';
1111

12+
// ISR: Revalidate every 12 hours
13+
export const revalidate = 43200;
14+
1215
export const metadata = createMetaData({
1316
title: 'Virtual Coffee Community Events',
1417
description: 'See our upcoming events!',

src/app/join/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import DefaultLayout from '@/components/layouts/DefaultLayout';
22
import { createMetaData } from '@/util/createMetaData.server';
33
import Link from 'next/link';
44

5+
// ISR: Revalidate every 24 hours
6+
export const revalidate = 86400;
7+
58
export const metadata = createMetaData({
69
title: 'Join Virtual Coffee',
710
description: `Virtual Coffee is an intimate community that welcomes people at all stages of their tech journey.`,

src/app/join/thank-you/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import DefaultLayout from '@/components/layouts/DefaultLayout';
22

3+
// ISR: Revalidate every 24 hours
4+
export const revalidate = 86400;
5+
36
export const metadata = {
47
title: 'Membership Form Received!',
58
description: `You're now on the membership waiting list!`,

src/app/members/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import 'leaflet/dist/leaflet.css';
1010
import { Suspense } from 'react';
1111
import { MapLoader, MapLoaderDev } from './map-loader';
1212

13+
// ISR: Revalidate every 24 hours
14+
export const revalidate = 86400;
15+
1316
export const metadata = createMetaData({
1417
title: 'Virtual Coffee Members',
1518
description: 'Meet our amazing members!',

src/app/monthlychallenges/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ import { getTotalPairingSessions } from '@/data/monthlyChallenges/pairing-challe
33
import { createMetaData } from '@/util/createMetaData.server';
44
import Link from 'next/link';
55

6+
// ISR: Revalidate every 24 hours
7+
export const revalidate = 86400;
8+
69
export const metadata = createMetaData({
710
title: 'Virtual Coffee Monthly Challenges',
811
description:

src/app/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import { getNewsletters } from '@/data/newsletters';
1111
import { getSponsors } from '@/data/sponsors';
1212
import { homePageLinks } from '@/util/homePageLinks';
1313

14+
// ISR: Revalidate every 12 hours
15+
export const revalidate = 43200;
16+
1417
export default async function Home() {
1518
const resources = loadMdxDirectory({
1619
baseDirectory: 'content/resources',

src/app/podcast/[slug]/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { sanitizeCmsData } from '@/util/sanitizeCmsData';
1010
import createCmsImage from '@/util/cmsimage';
1111
import { Metadata } from 'next';
1212

13+
// ISR: Revalidate every 24 hours
14+
export const revalidate = 86400;
15+
1316
export async function generateStaticParams() {
1417
const podcastEpisodes = await getEpisodes({ limit: 99 });
1518

src/app/podcast/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { getEpisodes } from '@/data/podcast';
66
import { createMetaData } from '@/util/createMetaData.server';
77
import createCmsImage from '@/util/cmsimage';
88

9+
// ISR: Revalidate every 24 hours
10+
export const revalidate = 86400;
11+
912
export const metadata = createMetaData({
1013
title: 'Virtual Coffee Podcast',
1114
description:

0 commit comments

Comments
 (0)