# ttl

> Simple in-memory cache for JavaScript

Latest version **1.3.1** (published 2017-11-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install ttl
pnpm add ttl
yarn add ttl
bun add ttl
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.1 |
| Published | 2017-11-20 |
| First published | 2014-10-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Rui Hu |
| Maintainers | mrhooray |
| Keywords | cache, caching, memory, in-memory, ttl |

## Links

- npm: https://www.npmjs.com/package/ttl
- Repository: https://github.com/mrhooray/ttl
- Issues: https://github.com/mrhooray/ttl/issues
- npm.io page: https://npm.io/package/ttl

## 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.3.1 (latest) — 2017-11-20
- 1.3.0 — 2015-02-25
- 1.2.0 — 2015-02-24
- 1.1.0 — 2015-02-24
- 1.0.1 — 2015-01-28
- 1.0.0 — 2014-10-22

## README

# ttl [![Build Status](https://travis-ci.org/mrhooray/ttl.svg?branch=master)](https://travis-ci.org/mrhooray/ttl)
> Simple in-memory cache for JavaScript

## Installation
```shell
$ npm install ttl --save
```

## Usage
```js
var Cache = require('ttl');
var cache = new Cache({
    ttl: 10 * 1000,
    capacity: 3
});

cache.on('put', function(key, val, ttl) { });
cache.on('del', function(key, val) { });
cache.on('drop', function(key, val, ttl) { });
cache.on('hit', function(key, val) { });
cache.on('miss', function(key) { });

cache.put('foo', 'bar');
cache.put('ping', 'pong', 20 * 1000);
cache.put('yo', 'yo', 30 * 1000);
cache.put('whats', 'up'); // emit 'drop' event

cache.get('foo');     // > 'bar'
cache.get('yo');      // > 'yo'
cache.get('ping');    // > 'pong'
cache.get('lol');     // > undefined

// after 10 seconds
cache.get('foo');     // > undefined
cache.size();         // > 2
cache.del('ping')     // > 'pong'
cache.get('ping');    // > undefined
cache.size();         // > 1
cache.clear();
cache.size();         // > 0
```

## License
MIT

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