mirror of
https://github.com/BradNut/personal-website-sveltekit
synced 2025-09-08 23:20:18 +00:00
Merge branch 'development' of github.com:BradNut/personal-website-sveltekit into svelteV5
This commit is contained in:
commit
4eea3803e2
3 changed files with 9 additions and 2 deletions
|
|
@ -48,12 +48,16 @@ export async function fetchArticlesApi(
|
||||||
});
|
});
|
||||||
|
|
||||||
if (USE_REDIS_CACHE) {
|
if (USE_REDIS_CACHE) {
|
||||||
|
console.log('Using redis cache');
|
||||||
const cached = await redis.get(entriesQueryParams.toString());
|
const cached = await redis.get(entriesQueryParams.toString());
|
||||||
|
|
||||||
if (cached) {
|
if (cached) {
|
||||||
|
console.log("Cache hit!");
|
||||||
const response = JSON.parse(cached);
|
const response = JSON.parse(cached);
|
||||||
const ttl = await redis.ttl(entriesQueryParams.toString());
|
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}` };
|
return { ...response, cacheControl: `max-age=${ttl}` };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,9 +11,10 @@ export async function fetchBandcampAlbums() {
|
||||||
|
|
||||||
if (cached) {
|
if (cached) {
|
||||||
const response: Album[] = JSON.parse(cached);
|
const response: Album[] = JSON.parse(cached);
|
||||||
|
console.log(`Cache hit!`);
|
||||||
const ttl = await redis.ttl('bandcampAlbums');
|
const ttl = await redis.ttl('bandcampAlbums');
|
||||||
|
|
||||||
return response;
|
return { ...response, cacheControl: `max-age=${ttl}` };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,13 @@ export async function GET({ setHeaders, url }) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetchArticlesApi('get', `fetchArticles`, {
|
const response = await fetchArticlesApi('get', 'fetchArticles', {
|
||||||
page,
|
page,
|
||||||
limit
|
limit
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log(`JSON articles response: ${JSON.stringify(response)}`);
|
||||||
|
|
||||||
if (response?.articles) {
|
if (response?.articles) {
|
||||||
if (response?.cacheControl) {
|
if (response?.cacheControl) {
|
||||||
if (!response.cacheControl.includes('no-cache')) {
|
if (!response.cacheControl.includes('no-cache')) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue