@@ -4,11 +4,9 @@ import { db } from '@/db';
44import { quizAnswers , quizQuestions } from '@/db/schema/quiz' ;
55import { getRedisClient } from '@/lib/redis' ;
66
7- const QUIZ_CACHE_TTL_SECONDS = 60 * 60 * 12 ;
8-
97interface QuizAnswersCache {
108 quizId : string ;
11- answers : Record < string , string > ; // questionId - correctAnswerId
9+ answers : Record < string , string > ;
1210 cachedAt : number ;
1311}
1412
@@ -22,18 +20,16 @@ export async function getOrCreateQuizAnswersCache(
2220 const redis = getRedisClient ( ) ;
2321 if ( ! redis ) {
2422 console . warn ( 'Redis not configured, skipping cache' ) ;
25- return true ; // Allow quiz to proceed without cache
23+ return true ;
2624 }
2725
2826 const key = getCacheKey ( quizId ) ;
2927
30- // Check if cache exists
3128 const existing = await redis . get < QuizAnswersCache > ( key ) ;
3229 if ( existing ) {
33- return true ; // Cache hit
30+ return true ;
3431 }
3532
36- // Fetch correct answers from DB
3733 const correctAnswers = await db
3834 . select ( {
3935 questionId : quizQuestions . id ,
@@ -60,7 +56,7 @@ export async function getOrCreateQuizAnswersCache(
6056 cachedAt : Date . now ( ) ,
6157 } ;
6258
63- await redis . set ( key , cacheData , { ex : QUIZ_CACHE_TTL_SECONDS } ) ;
59+ await redis . set ( key , cacheData ) ;
6460 return true ;
6561}
6662
@@ -69,7 +65,7 @@ export async function getCorrectAnswer(
6965 questionId : string
7066) : Promise < string | null > {
7167 const redis = getRedisClient ( ) ;
72-
68+
7369 if ( redis ) {
7470 const key = getCacheKey ( quizId ) ;
7571 const cache = await redis . get < QuizAnswersCache > ( key ) ;
@@ -78,7 +74,6 @@ export async function getCorrectAnswer(
7874 }
7975 }
8076
81- // DB fallback when Redis unavailable or cache miss
8277 const result = await db
8378 . select ( { answerId : quizAnswers . id } )
8479 . from ( quizAnswers )
@@ -94,4 +89,3 @@ export async function getCorrectAnswer(
9489
9590 return result [ 0 ] ?. answerId ?? null ;
9691}
97-
0 commit comments