import NodeCache from 'node-cache';

const cache = new NodeCache();

export const setCache = (key: string, value: unknown, ttl?: number) =>
  ttl ? cache.set(key, value, ttl) : cache.set(key, value);

export const getCache = <T>(key: string): T | undefined => cache.get<T>(key);

export const deleteCache = (key: string) => cache.del(key);

export const clearCache = () => cache.flushAll();

export const hasCache = (key: string) => cache.has(key);
