# memoize-methods

> Memoize methods of a given object

Latest version **1.0.1** (published 2021-02-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install memoize-methods
pnpm add memoize-methods
yarn add memoize-methods
bun add memoize-methods
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-02-11 |
| First published | 2020-01-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Vladimir Adamić |
| Maintainers | vunovati |
| Keywords | cache, memoize, proxy, weakmap, typescript, async |

## Links

- npm: https://www.npmjs.com/package/memoize-methods
- Repository: https://github.com/Vunovati/memoize-methods
- Homepage: https://github.com/Vunovati/memoize-methods#readme
- Issues: https://github.com/Vunovati/memoize-methods/issues
- npm.io page: https://npm.io/package/memoize-methods

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2021-02-11
- 1.0.0 (prerelase) — 2020-01-21

## README

# memoize-methods

Memoize methods of a given JavaScript object

[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![NPM](https://nodei.co/npm/memoize-methods.png?mini=true)](https://npmjs.org/package/memoize-methods)

## 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
```

---
_Source: https://npm.io/package/memoize-methods · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
