feat: unified cache handler

This commit is contained in:
Huskydog9988
2025-05-07 22:13:22 -04:00
parent 5aa0899bcf
commit 731499be81
7 changed files with 86 additions and 34 deletions
+6 -4
View File
@@ -2,15 +2,17 @@
Handles managing collections
*/
import cacheHandler from "../cache";
import prisma from "../db/database";
class UserLibraryManager {
// Caches the user's core library
private userCoreLibraryCache: { [key: string]: string } = {};
private coreLibraryCache =
cacheHandler.createCache<string>("UserCoreLibrary");
private async fetchUserLibrary(userId: string) {
if (this.userCoreLibraryCache[userId])
return this.userCoreLibraryCache[userId];
const cached = await this.coreLibraryCache.get(userId);
if (cached !== null) return cached;
let collection = await prisma.collection.findFirst({
where: {
@@ -28,7 +30,7 @@ class UserLibraryManager {
},
});
this.userCoreLibraryCache[userId] = collection.id;
await this.coreLibraryCache.set(userId, collection.id);
return collection.id;
}