memoize-methods
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

memoize-methods

Memoize methods of a given JavaScript object

code style: prettier NPM

usage

Initialize the memoization store. The store will keep the memoized objects for as long as the originals are not garbage collected (it uses a WeakMap).

const memoizeMethods = createMemoizeMethods()
const memoizedUserRepository = memoizeMethods(slowUserDbRepository)

the first call will be as slow as if we'd called the original user repo

const user = await memoizedUserRepository.getUser(userId) // slow

the second call will return the promise from the previous call which prevents the unnecessary repeated async call (e.g. towards a slow db)

const userFast = await memoizedUserRepository.getUser(userId) // fast

/memoize-methods/

    Package Sidebar

    Install

    npm i memoize-methods

    Weekly Downloads

    4

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    6.85 kB

    Total Files

    5

    Last publish

    Collaborators

    • vunovati