1.1.2 • Published 5 years ago

uber-memoize v1.1.2

Weekly downloads
99
License
BSD*
Repository
github
Last release
5 years ago

Async memoize for uber-cache-* engines

build status

If you want to know about memoization read this http://en.wikipedia.org/wiki/Memoization

Installation

npm install uber-memoize

Example

function slowFn(i, cb) {
  // Takes 5 seconds
  setTimeout(cb, 5000)
}

var UberCache = require('uber-cache')
  , uberMemoize = require('uber-memoize')
  , uberCache = new UberCache()

  // You can use any uber-cache-* engine to power memoize
  , memoize = uberMemoize('some sort of prefix', uberCache)
  , ttl = 10000 // 10 Seconds
  , cachedSlowFn = memoize(slowFn, ttl)

  // This first call will be slow
  cachedSlowFn(1, function(err, result) {
    // It will take 5 seconds to get here!
    cachedSlowFn(1, function(err, result) {
      // This will be quick!
    })
  })
})

// The memoized function comes with a clear() method which will invalidate
// its cache, ensuring that the next call executes the original function
cachedSlowFn.clear()
cachedSlowFn(1, function (err, result) {
  // This will take 5 seconds again
})

Credits

Paul Serby follow me on twitter

Licence

Licenced under the New BSD License

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

9 years ago

1.0.0

9 years ago

0.0.3

9 years ago

0.0.1

9 years ago