# hooked-ttl-map

> ttl map with a cleanup hook

Latest version **0.0.0** (published 2018-10-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install hooked-ttl-map
pnpm add hooked-ttl-map
yarn add hooked-ttl-map
bun add hooked-ttl-map
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.0 |
| Published | 2018-10-09 |
| First published | 2018-10-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Noah Anabiik Schwarz |
| Maintainers | chiefbiiko |
| Keywords | cache, map, ttl, hook, cleanup, safe |

## Links

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

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

- 0.0.0 (latest) — 2018-10-09

## README

# hooked-ttl-map

[![build status](http://img.shields.io/travis/chiefbiiko/hooked-ttl-map.svg?style=flat)](http://travis-ci.org/chiefbiiko/hooked-ttl-map) [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/chiefbiiko/hooked-ttl-map?branch=master&svg=true)](https://ci.appveyor.com/project/chiefbiiko/hooked-ttl-map)

***

A `Map` subtype to be used as a temporary cache allowing for cleanup operations before any item is deleted from the map through a `willDelete` hook.

***

## Get it!

```
npm install --save hooked-ttl-map
```

***

## Usage

``` js
var HookedTtlMap = require('hooked-ttl-map')
var cache = new HookedTtlMap()

cache.set(27, 'fraud', 419) // time-to-live, key, value

console.log(cache, cache.size)

setTimeout(function () {
  console.log(cache, cache.size) // will be empty
}, 28)
```

***

## API

### `var cache = new HookedTtlMap([ttl, iterable][, willDelete(key, value, doDelete)])`

Create a new `HookedTtlMap` instance. If `iterable` is provided (must be a 2d array) all passed items get added to the map during instantiation, and deleted after `ttl`. If `willDelete` is a function it will be called as a cleanup hook before items are deleted from the set but after `ttl` has exceeded. Make sure to call the `doDelete` callback at the end of the `willDelete` hook to actually perform the deletion.

### `cache.set(ttl, key, value[, willDelete(key, value, doDelete)])`

Provide `ttl`, time to live in ms, a `key`, and a `value` that will get deleted from the map at the end of their lifetime. If the last argument is a function it will be called as a cleanup hook before valules are deleted from the map but after `ttl` has exceeded. Make sure to call the `doDelete` callback at the end of the `willDelete` hook to actually perform the deletion.

***

## License

[MIT](./license.md)

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