Skip to content

Commit

Permalink
fix: remove cache
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinWu098 committed Jan 26, 2025
1 parent 7cb6317 commit f79ba2a
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/lib/utils/query-db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ export type DatabaseReturn = {
lastUpdated: number;
};

const cache: Record<string, [Date, DatabaseReturn]> = {};
const cache: Record<string, [number, DatabaseReturn]> = {};
const THIRTY_MINUTES = 30 * 60 * 1000;

console.log(THIRTY_MINUTES);

export async function queryDatabase(
university: string,
Expand All @@ -16,14 +19,15 @@ export async function queryDatabase(

const cacheKey = universityParam + geParam;

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

// If not older than 30 minutes, return cached courses
if ((new Date().getTime() - cachedDate.getTime()) / (1000 * 60) <= 30) {
return cachedData;
}
}
// if (Date.now() - cachedDate <= THIRTY_MINUTES) {
// console.log(cachedData);
// return cachedData;
// }
// }

const universityUri = encodeURIComponent(universityParam);
const geUri = encodeURIComponent(geParam);
Expand All @@ -39,7 +43,9 @@ export async function queryDatabase(
const data = await response.json();
const output = { data: data.data, lastUpdated: data.lastUpdated };

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

console.log(output.lastUpdated);

return output;
} catch (error) {
Expand Down

0 comments on commit f79ba2a

Please sign in to comment.