Skip to content

Commit

Permalink
fix: disable cache
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 committed Feb 1, 2025
1 parent a385a14 commit 8adb4ae
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/lib/utils/query-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ export type DatabaseReturn = {
const cache: Record<string, [number, DatabaseReturn]> = {};
const THIRTY_MINUTES = 30 * 60 * 1000;

console.log(THIRTY_MINUTES);

export async function queryDatabase(
university: string,
ge: string
Expand All @@ -19,23 +17,24 @@ export async function queryDatabase(

const cacheKey = universityParam + geParam;

// if (cache[cacheKey]) {
// const [cachedDate, cachedData] = cache[cacheKey];
// console.log(cachedDate);
if (cache[cacheKey]) {
const [cachedDate, cachedData] = cache[cacheKey];
console.log(cachedDate);

// if (Date.now() - cachedDate <= THIRTY_MINUTES) {
// console.log(cachedData);
// return cachedData;
// }
// }
if (Date.now() - cachedDate <= THIRTY_MINUTES) {
return cachedData;
}
}

const universityUri = encodeURIComponent(universityParam);
const geUri = encodeURIComponent(geParam);

const url = `https://i-did-ur.mom/api/cvc-courses?institution=${universityUri}&ge=${geUri}`;

try {
const response = await fetch(url);
const response = await fetch(url, {
cache: "no-cache",
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
Expand All @@ -45,8 +44,6 @@ export async function queryDatabase(

cache[cacheKey] = [Date.now(), output];

console.log(output.lastUpdated);

return output;
} catch (error) {
console.error("Error:", error);
Expand Down

0 comments on commit 8adb4ae

Please sign in to comment.