lru-cache-decorator
v1.2.0
Published
LRU Cache function decorator based on arguments
Downloads
19
Readme
LRU Cache Decorator
A decorator that caches functions.
- Supports both sync and async functions.
- Supports hashing the function arguments - only necessary if you have really long/large function arguments.
API
const decorate = require('lru-cache-decorator')
fn = decorate(options)(fn)
Options are passed to lru-cache
.
Other options:
async = false
- whether the function is async (i.e. uses promises)- Caches functions as sync by default, but async functions would still work
- Sync functions do not cache errors while async functions do since it's stored as a rejected promise
hash = Algorithm<String>|<Function>
- a function to hash the stringified function arguments. You can also supply a hashing function algorithm such assha256
cacheErrors = true
- whenfalse
andasync=true
, errors are not cached.