forked from FoundKeyGang/FoundKey
Johann150
d1ec058d5c
Instead of having to pass the fetcher every time you want to fetch something, the fetcher is stored in an attribute of the Cache.
14 lines
428 B
TypeScript
14 lines
428 B
TypeScript
import { UserKeypairs } from '@/models/index.js';
|
|
import { User } from '@/models/entities/user.js';
|
|
import { UserKeypair } from '@/models/entities/user-keypair.js';
|
|
import { Cache } from './cache.js';
|
|
|
|
const cache = new Cache<UserKeypair>(
|
|
Infinity,
|
|
(userId) => UserKeypairs.findOneByOrFail({ userId }),
|
|
);
|
|
|
|
export async function getUserKeypair(userId: User['id']): Promise<UserKeypair> {
|
|
return await cache.fetch(userId);
|
|
}
|