1.2.0 • Published 9 years ago
lru-cache-decorator v1.2.0
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 assha256cacheErrors = true- whenfalseandasync=true, errors are not cached.