Skip to content

Commit 06ab629

Browse files
committed
cache update
1 parent 132b3ca commit 06ab629

2 files changed

Lines changed: 52 additions & 19 deletions

File tree

index.js

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -260,27 +260,39 @@ app.get("/events/:slug", async (req,res) => {
260260

261261

262262
})
263-
app.get("/poetic-promenade", async (req,res) => {
264-
//filter by slug here
265-
const eventData = await getDatabaseEntry("10c62665c6ca4383bbdc12788c45df14", {property:"Website-Slug", "rich_text": {"equals":"poetic-promenade"}})
266-
if(!eventData) return
263+
app.get("/poetic-promenade", async (req, res) => {
264+
const cacheKey = "cache:event:poetic-promenade";
267265

268-
// console.log(response)
266+
try {
267+
if (redisIsReady) {
268+
// 1. Try to get from Cache
269+
const cachedData = await client.get(cacheKey);
270+
271+
if (cachedData) {
272+
// Serve immediately
273+
const parsedCache = JSON.parse(cachedData);
274+
res.render("programs/prom", parsedCache);
275+
276+
// Background Update (SWR)
277+
revalidatePromenadeData(cacheKey).catch(console.error);
278+
return;
279+
}
280+
}
269281

270-
const response = await prepareEventData(eventData, "poetic-promenade")
271-
console.log(response)
272-
res.render("programs/prom", response)
273-
274-
//
275-
// if(eventData){
276-
//
277-
// res.render("programs/eventPage", response)
278-
//
279-
// }
280-
//
282+
// 2. Cache Miss or Redis Offline: Fetch live
283+
const freshData = await revalidatePromenadeData(cacheKey);
281284

285+
if (freshData) {
286+
res.render("programs/prom", freshData);
287+
} else {
288+
res.status(404).send("Event not found");
289+
}
282290

283-
})
291+
} catch (error) {
292+
console.error("Promenade Route Error:", error);
293+
res.status(500).send("Internal Server Error");
294+
}
295+
});
284296
app.get("/", async (req,res) => {
285297
// const response = await getDatabaseEntries("16ea90c83765437c86f87bd13a205ca6", [{property:"Date", direction:"descending"}])
286298
// const testimonialData = response.map((testimonial) => {
@@ -2550,4 +2562,25 @@ async function revalidateBlogData(slug, cacheKey) {
25502562

25512563

25522564
return finalData;
2565+
}
2566+
async function revalidatePromenadeData(cacheKey) {
2567+
// 1. Fetch from Notion
2568+
const eventData = await getDatabaseEntry("10c62665c6ca4383bbdc12788c45df14", {
2569+
property: "Website-Slug",
2570+
rich_text: { "equals": "poetic-promenade" }
2571+
});
2572+
2573+
if (!eventData) return null;
2574+
2575+
// 2. Process data using your existing helper
2576+
const response = await prepareEventData(eventData, "poetic-promenade");
2577+
2578+
// 3. Store in Redis if active
2579+
if (redisIsReady) {
2580+
await client.set(cacheKey, JSON.stringify(response), {
2581+
EX: 3500 // 1 hour TTL
2582+
});
2583+
}
2584+
2585+
return response;
25532586
}

public/templates/programs/prom.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
h1 {
4545
font-family: var(--prom-26-title-font) !important;
4646
}
47-
.special-button {
47+
.special-button, .fixed-apply {
4848
font-family: var(--prom-26-body-font) !important;
4949
}
5050
</style>
@@ -81,7 +81,7 @@
8181

8282
<div id="class" class="event hide-content appsClosed beforeClass shell-content">
8383

84-
84+
<a class="fixed-apply hide-apply " href="{{"External-Website"}}">Get Tickets</a>
8585
<section id="section-class-details">
8686
<div class="grid-2">
8787
<h1><span id="class-name" style="font-family: var(--prom-26-title-font) !important; font-size:2em">

0 commit comments

Comments
 (0)