Merge branch 'development' of github.com:BradNut/personal-website-sveltekit into svelteV5

This commit is contained in:
Bradley Shellnut 2024-12-19 10:54:32 -08:00
commit 4eea3803e2
3 changed files with 9 additions and 2 deletions

View file

@ -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}` };
}
}

View file

@ -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}` };
}
}

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