add cache to auth

This commit is contained in:
2025-01-24 19:24:27 +05:30
parent 59ce61d3a6
commit 405338c314
8 changed files with 125 additions and 67 deletions

19
src/utils/cache.ts Normal file
View File

@@ -0,0 +1,19 @@
import { LRUCache } from "lru-cache";
import { AuthenticatedUser } from "../auth";
const sessionCache = new LRUCache<string, AuthenticatedUser>({
max: 100,
ttl: 1000 * 60 * 60,
});
export function cacheSession(key: string, user: AuthenticatedUser) {
sessionCache.set(key, user);
}
export function getCachedSession(key: string) {
return sessionCache.get(key);
}
export function removeCachedSession(key: string) {
sessionCache.delete(key);
}