# mini-memoize

> A simple memoization library, The volume is very small.

Latest version **1.0.5** (published 2021-11-18) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2021-11-18 |
| First published | 2021-08-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 11.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | HuangZhaoPing |
| Maintainers | huangzhaoping |
| Keywords | memoize, cache |

## Links

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

## 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.5 (latest) — 2021-11-18
- 1.0.4 — 2021-08-18
- 1.0.3 — 2021-08-05
- 1.0.2 — 2021-08-05
- 1.0.1 — 2021-08-04
- 1.0.0 — 2021-08-03

## README

# mini-memoize

A simple memoization library, The volume is very small.

## Usage

```js
import memoize from 'mini-memoize'

function add (a, b) {
  return a + b
}
const memoizeAdd = memoize(add)
memoizeAdd(1, 2) // excute
memoizeAdd(1, 2) // hit cache
memoizeAdd(1, 3) // excute
memoizeAdd(1, 3) // hit cache
```

## promise

```js
import memoize from 'mini-memoize'

function promise (a, b) {
  return new Promise(resolve => {
    setTimeout(() = {
      resolve(a + b)
    }, 3000)
  })
}
const memoizePromise = memoize(promise)
memoizePromise(1, 3).then(res => (console.log(res))) // excute
memoizePromise(1, 3).then(res => (console.log(res))) // hit cache
setTimeout(() = {
  memoizePromise(1, 3).then(res => (console.log(res))) // hit cache
}, 3000)
```

## get

```js
function add (a, b) {
  return a + b
}
const memoizeAdd = memoize(add)
memoizeAdd.get(1, 2) // undefined
memoizeAdd(1, 2) // 3
memoizeAdd.get(1, 2) // 3
```

## has

```js
function add (a, b) {
  return a + b
}
const memoizeAdd = memoize(add)
memoizeAdd(1, 2) // 3
memoizeAdd.has(1, 2) // true
memoizeAdd.has(1, 3) // false
```

## delete

```js
import memoize from 'mini-memoize'

function add (a, b) {
  return a + b
}
const memoizeAdd = memoize(add)
memoizeAdd(1, 2) // excute
memoizeAdd(1, 2) // hit cache
memoizeAdd.delete(1, 2) // delete
memoizeAdd(1, 2) // excute
memoizeAdd(1, 2) // hit cache
memoizeAdd.clear() // delete all
memoizeAdd(1, 2) // excute
```

## max cache

```js
import memoize from 'mini-memoize'

function add (a, b) {
  return a + b
}
const memoizeAdd = memoize(add, { max: 2 })
memoizeAdd(1, 2) // excute
memoizeAdd(1, 3)
memoizeAdd(1, 4)
memoizeAdd(1, 2) // excute
```

## event

```js
import memoize from 'mini-memoize'

function add (a, b) {
  return a + b
}
const memoizeAdd = memoize(add)

function handler (args) {
  console.log(args)
}

// on，type: get、delete、clear
memoizeAdd.on('delete', handler)

// off
memoizeAdd.off('delete', handler)
```

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