# expiry-map

> A Map implementation with expirable items

Latest version **2.0.0** (published 2022-02-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install expiry-map
pnpm add expiry-map
yarn add expiry-map
bun add expiry-map
```

## 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 | 2.0.0 |
| Published | 2022-02-08 |
| First published | 2018-08-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 1 |
| Unpacked size | 6.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 91 |
| Author | Sam Verschueren |
| Maintainers | samverschueren |
| Keywords | map, cache, caching, ttl, expire, expiring, expiry |

## Links

- npm: https://www.npmjs.com/package/expiry-map
- Repository: https://github.com/SamVerschueren/expiry-map
- Homepage: https://github.com/SamVerschueren/expiry-map#readme
- Issues: https://github.com/SamVerschueren/expiry-map/issues
- npm.io page: https://npm.io/package/expiry-map

## Dependencies (1)

- [map-age-cleaner](https://npm.io/package/map-age-cleaner.md) ^0.2.0

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

- 2.0.0 (latest) — 2022-02-08
- 1.1.0 — 2018-08-21
- 1.0.2 — 2018-08-15
- 1.0.1 — 2018-08-14
- 1.0.0 — 2018-08-14

## README

# expiry-map

![CI](https://github.com/SamVerschueren/expiry-map/workflows/CI/badge.svg) [![codedov](https://codecov.io/gh/SamVerschueren/expiry-map/branch/master/graph/badge.svg)](https://codecov.io/gh/SamVerschueren/expiry-map)

> A [`Map`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) implementation with expirable items

Memory is automatically released when an item expires by removing it from the `Map`.


## Install

```
$ npm install expiry-map
```


## Usage

```js
import ExpiryMap = require('expiry-map');

const map = new ExpiryMap(1000, [
	['unicorn', '🦄']
]);

map.get('unicorn');
//=> 🦄

map.set('rainbow', '🌈');

console.log(map.size);
//=> 2

// Wait for 1 second...
map.get('unicorn');
//=> undefined

console.log(map.size);
//=> 0
```


## API

### ExpiryMap(maxAge, [iterable])

#### maxAge

Type: `number`

Milliseconds until an item in the `Map` expires.

#### iterable

Type: `Object`

An `Array` or other `iterable` object whose elements are key-value pairs.

### Instance

Any of the [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) methods.


## Related

- [expiry-set](https://github.com/SamVerschueren/expiry-set) - A `Set` implementation with expirable keys
- [map-age-cleaner](https://github.com/SamVerschueren/map-age-cleaner) - Automatically cleanup expired items in a Map


## License

MIT © [Sam Verschueren](https://github.com/SamVerschueren)

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