24 lines
585 B
TypeScript
Executable File
24 lines
585 B
TypeScript
Executable File
import { CACHE_MANAGER, Cache } from "@nestjs/cache-manager";
|
|
import { Inject, Injectable } from "@nestjs/common";
|
|
|
|
@Injectable()
|
|
export class CacheService {
|
|
constructor(@Inject(CACHE_MANAGER) private cacheManager: Cache) {}
|
|
|
|
async get<T>(key: string) {
|
|
return await this.cacheManager.get<T>(key);
|
|
}
|
|
|
|
async set(key: string, value: string, ttl: number = 120 * 1000) {
|
|
await this.cacheManager.set(key, value, ttl);
|
|
}
|
|
|
|
async del(key: string) {
|
|
await this.cacheManager.del(key);
|
|
}
|
|
|
|
async getTtl(key: string) {
|
|
return await this.cacheManager.ttl(key);
|
|
}
|
|
}
|