# tlru-cache

> Time aware least recently used cache storage

Latest version **1.0.0** (published 2018-10-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install tlru-cache
pnpm add tlru-cache
yarn add tlru-cache
bun add tlru-cache
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-10-07 |
| First published | 2018-10-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | z3ut |
| Keywords | cache, storage, tlru |

## Links

- npm: https://www.npmjs.com/package/tlru-cache
- npm.io page: https://npm.io/package/tlru-cache

## 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.0 (latest) — 2018-10-07

## README

TLRU-Cache
=

Time aware least recently used cache store

## Installation

```
npm i tlru-cache
```

## Usage

```typescript
import { TLRUCache } from 'tlru-cache';

const tlruCache =  new TLRUCache({
  // optional values
  maxStoreSize: 5,
  timeToUseMs: 60 * 1000,
});

const value = tlruCache.get('value', () => 42);
// won't calculate again
const sameValue = tlruCache.get('value', () => 42);
```

## Documentation

### Constructor object properties:

Name | Type | Default value | Description
---|---|---|---
maxStoreSize | number | 1000 | Store capacity
maxAgeMs | number | 60 * 60 * 1000 (1 hour) | Record time to use in milliseconds. Put <= 0 for non-expiring records.

### Methods:

```typescript
get<TKey, TValue>(key: TKey, calculate: (key: TKey) => TValue, maxAgeMs: number = null): TValue
```

#### Arguments:

* **key**: record key

* **calculate**: function to get record. receive key as argument

* **maxAgeMs**: record time to use. if presented, override constructor option

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