// src/cache/cache.service.ts
import { Injectable } from '@nestjs/common';
import * as NodeCache from 'node-cache';

@Injectable()
export class CacheService {
  private cache = new NodeCache({ stdTTL: 60 * 5 }); // 5 phút

  get<T>(key: string): T | undefined {
    return this.cache.get(key);
  }

  set<T>(key: string, value: T, ttl: number | string = 10000) {
    this.cache.set(key, value, ttl);
  }

  del(key: string) {
    this.cache.del(key);
  }

  flush() {
    this.cache.flushAll();
  }
}
