-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
757164e
commit 883db5c
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { StudentPlans } from "../info/Plans.js"; | ||
import type { Plans } from "../info/PlansType.js"; | ||
import type { AuthMethod, Method } from "../utils/Method.js"; | ||
|
||
type ClassCache<Val> = Map<typeof AuthMethod | typeof Method, Val>; | ||
export class Cache{ | ||
private _Cache: Map<string, ClassCache<any>> = new Map(); | ||
lastUpdate: Date = new Date(); | ||
|
||
getCache<R>(c: typeof AuthMethod | typeof Method, studentCode: string){ | ||
return this._Cache.get(studentCode)?.get(c) as R; | ||
} | ||
|
||
setCache<I>(student: string, c: typeof AuthMethod | typeof Method, value: I){ | ||
const prev = this._Cache.get(student); | ||
if(!prev){ | ||
const _Cache = new Map<typeof AuthMethod | typeof Method, I>(); | ||
_Cache.set(c, value); | ||
this._Cache.set(student, _Cache); | ||
return; | ||
} | ||
prev.set(c, value); | ||
} | ||
|
||
clearCache(student: string){ | ||
this._Cache.delete(student); | ||
} | ||
|
||
getPlanfromCache(student: string): Plans | undefined{ | ||
return this.getCache(StudentPlans as typeof AuthMethod, student); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters