mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-26 01:34:38 +10:00
feat: unified cache handler
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user