Skip to content

lirown/lru-cache-decorator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LRU Cache Decorator

NPM version Build status Test coverage Dependency Status License Downloads

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 as sha256
  • cacheErrors = true - when false and async=true, errors are not cached.

About

lru-cache as a decorator function

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%