its-caching-time
Cache your expensive code
Usage
opts
: Object
storage
,object(set(key, val), get(key), del(key))
: Simple KV storage interfacestoreAsString
,boolean
: Store data as string instead of raw JS values
Result:
.set(key, val, ttl)
: Store the valueval
underkey
forttl
ms.get(key)
: Getkey
if it's still valid.del(key)
: Delete/Expirekey
prematurely
const caching = // create a new in-memory cacheconst cache = // create a new cached entryawait cache // caches 'theAnswer' for 300ms // create a new cached function 'calc' which will cache for 3sconst cachedFunction = cache // create a new cached function 'fetch' which will cache for 3s and re-fetch in the backgroundconst fetchFnc = cacheconst content = await