Console log.

This commit is contained in:
Bradley Shellnut 2024-12-13 13:21:19 -08:00
parent 17d8498e2a
commit 9ec7b8c188
2 changed files with 7 additions and 1 deletions

View file

@ -44,12 +44,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}` };
}
}

View file

@ -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')) {