@@ -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+ } ) ;
284296app . 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}
0 commit comments