# async-memoize-one

> memoize the last result, in async way

Latest version **1.2.1** (published 2026-04-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install async-memoize-one
pnpm add async-memoize-one
yarn add async-memoize-one
bun add async-memoize-one
```

## Health

**Score 60/100 (C)** — status: active.

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

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.2.1 |
| Published | 2026-04-14 |
| First published | 2020-12-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >= 12 |
| Dependencies | 1 |
| Unpacked size | 8.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 28 |
| Author | microlink.io |
| Maintainers | kikobeats |
| Keywords | api, async, asynchronous, cache, cache, call, memoization, memoization, memoize, memoize, performance |

## Links

- npm: https://www.npmjs.com/package/async-memoize-one
- Repository: https://github.com/microlinkhq/async-memoize-one
- Issues: https://github.com/microlinkhq/async-memoize-one/issues
- npm.io page: https://npm.io/package/async-memoize-one

## Dependencies (1)

- [fast-deep-equal](https://npm.io/package/fast-deep-equal.md) ~3.1.3

## 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.2.1 (latest) — 2026-04-14
- 1.2.0 — 2026-03-04
- 1.1.9 — 2025-08-12
- 1.1.8 — 2024-05-09
- 1.1.7 — 2024-02-09
- 1.1.6 — 2023-10-24
- 1.1.5 — 2023-09-07
- 1.1.4 — 2023-09-07
- 1.1.3 — 2023-05-13
- 1.1.2 — 2022-07-22
- 1.1.1 — 2022-05-15
- 1.1.0 — 2021-03-08
- 1.0.1 — 2020-12-02
- 1.0.0 — 2020-12-02

## README

<div align="center">
  <img src="https://github.com/microlinkhq/cdn/raw/master/dist/logo/banner.png#gh-light-mode-only" alt="microlink logo">
  <img src="https://github.com/microlinkhq/cdn/raw/master/dist/logo/banner-dark.png#gh-dark-mode-only" alt="microlink logo">
  <br>
  <br>
</div>

![Last version](https://img.shields.io/github/tag/microlinkhq/async-memoize-one.svg?style=flat-square)
[![Coverage Status](https://img.shields.io/coveralls/microlinkhq/async-memoize-one.svg?style=flat-square)](https://coveralls.io/github/microlinkhq/async-memoize-one)
[![NPM Status](https://img.shields.io/npm/dm/async-memoize-one.svg?style=flat-square)](https://www.npmjs.org/package/async-memoize-one)

> Memoize the last result, in async way.

**async-memoize-one** simply remembers the last arguments, and if the function is next called with the same arguments then it returns the previous result.

It's used for [micro-caching](https://www.nginx.com/blog/benefits-of-microcaching-nginx/) scenarios, where you want to prevent perform an action previously done during a short period of time.

No need to worry about cache busting mechanisms such as maxAge, maxSize, exclusions and so on which can be prone to memory leaks.

## Install

```bash
$ npm install async-memoize-one --save
```

## Usage

```js
const get = require('util').promisify(require('simple-get'))
const memoizeOne = require('async-memoize-one')

const fetchData = memoizeOne(url => get(`https://api.microlink.io?url=${url}`))

;(async () => {
  // fecthing data for first time
  console.time('fetch')
  await fetchData('https://example.com/one')
  console.timeEnd('fetch')

  // served data from cache; no fetching!
  console.time('fetch')
  await fetchData('https://example.com/one')
  console.timeEnd('fetch')

  // previous execution parameters are different, so fetching again
  console.time('fetch')
  await fetchData('https://example.com/two')
  console.timeEnd('fetch')

  // previous execution parameters are different, so fetching again
  console.time('fetch')
  await fetchData('https://example.com/one')
  console.timeEnd('fetch')
})()
```

## API

### memoizeOne(fn, [isEqual], [options])

#### fn

*Required*<br>
Type: `function`

Promise-returning or async function to be memoized.

#### isEqual

Type: `function`<br>
Default: [`fast-deep-equal`](https://github.com/epoberezkin/fast-deep-equal)

The compare function to determinate if both executions are the same.

An equality function should return true if the arguments are equal. If true is returned then the wrapped function will not be called.

#### options

##### cachePromiseRejection

Type: `boolean`<br>
Default: `false`

Cache rejected promises.

## License

**async-memoize-one** © [microlink.io](https://microlink.io), released under the [MIT](https://github.com/microlinkhq/async-memoize-one/blob/master/LICENSE.md) License.<br>
Authored and maintained by [Kiko Beats](https://kikobeats.com) with help from [contributors](https://github.com/microlinkhq/async-memoize-one/contributors).

> [microlink.io](https://microlink.io) · GitHub [microlink.io](https://github.com/microlinkhq) · X [@microlinkhq](https://x.com/microlinkhq)

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