diff --git a/src/lib/api.ts b/src/lib/api.ts index 57b1a3b..b0967a9 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -48,12 +48,16 @@ export async function fetchArticlesApi( }); if (USE_REDIS_CACHE) { + console.log('Using redis cache'); const cached = await redis.get(entriesQueryParams.toString()); if (cached) { + console.log("Cache hit!"); const response = JSON.parse(cached); const ttl = await redis.ttl(entriesQueryParams.toString()); + console.log(`Response ${JSON.stringify(response)}`); + console.log(`Returning cached response with ttl of ${ttl} seconds`); return { ...response, cacheControl: `max-age=${ttl}` }; } } diff --git a/src/lib/util/fetchBandcampAlbums.ts b/src/lib/util/fetchBandcampAlbums.ts index 947ba8c..a5ee39f 100644 --- a/src/lib/util/fetchBandcampAlbums.ts +++ b/src/lib/util/fetchBandcampAlbums.ts @@ -11,9 +11,10 @@ export async function fetchBandcampAlbums() { if (cached) { const response: Album[] = JSON.parse(cached); + console.log(`Cache hit!`); const ttl = await redis.ttl('bandcampAlbums'); - return response; + return { ...response, cacheControl: `max-age=${ttl}` }; } } diff --git a/src/routes/api/articles/+server.ts b/src/routes/api/articles/+server.ts index d0733b1..cbad32e 100644 --- a/src/routes/api/articles/+server.ts +++ b/src/routes/api/articles/+server.ts @@ -10,11 +10,13 @@ export async function GET({ setHeaders, url }) { } try { - const response = await fetchArticlesApi('get', `fetchArticles`, { + const response = await fetchArticlesApi('get', 'fetchArticles', { page, limit }); + console.log(`JSON articles response: ${JSON.stringify(response)}`); + if (response?.articles) { if (response?.cacheControl) { if (!response.cacheControl.includes('no-cache')) {