A simple caching module
npm install @vates/simple-cache
set(key, data, ttl?)
import Cache from '@vates/simple-cache';
const emailsCache = new Cache()
emailsCache.set("customer123", "customer123@mail.com")
get(key)
cache.get("customer123")
//=> { data: 'customer123@mail.com', date: 1715870399907, expireAt: 1715870419907 }
Caches the return of a function
withCache(function, args = [], options = {expireAt, key})
cache.withCache(fetch, [url, { method: "POST" }], { expireAt: 5000 });
//=> data
isExpired(key)
cache.isExpired("customer123")
//=> true/false
clearCache(key?)
cache.clearCache("customer123")
cache.clearCache()