@vates/simple-cache
v1.2.0
Published
simple cache
Downloads
3
Maintainers
Keywords
Readme
@vates/simple-cache
A simple caching module
Install
npm install @vates/simple-cache
Usage
Set a key
set(key, data, ttl?)
import Cache from '@vates/simple-cache';
const emailsCache = new Cache()
emailsCache.set("customer123", "[email protected]")
Get a key
get(key)
cache.get("customer123")
//=> { data: '[email protected]', date: 1715870399907, expireAt: 1715870419907 }
Cache function
Caches the return of a function
withCache(function, args = [], options = {expireAt, key})
cache.withCache(fetch, [url, { method: "POST" }], { expireAt: 5000 });
//=> data
IsExpired
isExpired(key)
cache.isExpired("customer123")
//=> true/false
Clear cache
clearCache(key?)
cache.clearCache("customer123")
cache.clearCache()