Evo.Auth/apps/api/src/users/users.cache.ts
2023-10-14 15:57:45 +03:00

23 lines
651 B
TypeScript

import type { User } from '../types/user';
import { CACHE_MANAGER } from '@nestjs/cache-manager';
import { Inject, Injectable } from '@nestjs/common';
import { Cache } from 'cache-manager';
@Injectable()
export class UsersCache {
constructor(@Inject(CACHE_MANAGER) private readonly cacheManager: Cache) {}
async getUser(username: string) {
return (await this.cacheManager.get(username)) as User;
}
async addUser(username: string, user: User) {
await this.cacheManager.set(username, user);
}
async deleteUser(username: string) {
if (this.cacheManager.get(username)) {
await this.cacheManager.del(username);
}
}
}