yet another cache
Why the heck does the world need another caching module? Well, it probably doesn't but while working on http-asset part of me was feeling crazy, part of me was feeling ambitious, and the rest of me was too lazy to sift through all the caching modules on NPM to find the one that best fit the bill.
So, I offer you ya-cache.
features
- super simple api
- file system backed
- cache is just JSON in a file
- file system locking ¯\_(ツ)_/¯
example
let Cache = let thingCache = const HOUR = 1000 * 60 * 60 let expires thing = thingCacheif expires && expires < Date thing = await await thingCache
api
new Cache(path, lockFileOptions = {})
Constructs a cache object, provides the api to each cache
cache.get([key]) -> Promise
Get the value of a key, returns a promise. If the key argument is undefined then all keys and their values are returned in an object.
cache
cache.set(key, val) -> Promise
Set the value of a key, returns a promise.
cache
cache.gets(...keys) -> Promise
Get one or more keys, returns a promise that resolves to an array of values.
cache
cache.sets({ key: value ... }) -> Promise
Set one of more keys, returns a promise that resolves to an object of the saved values.
cache
cache.clear([key]) -> Promise
Clear a key in the cache. If the key is undefined then all keys are cleared
cachecacheclear'foo'cache