# an-lru-cache

> A simple LRU Cache, a Map that has a maximum number of entries and which discards the least recently used items first.

Latest version **1.0.5** (published 2018-06-11) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install an-lru-cache
pnpm add an-lru-cache
yarn add an-lru-cache
bun add an-lru-cache
```

## 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.0.5 |
| Published | 2018-06-11 |
| First published | 2018-02-15 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 23.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | @mikesamuel |
| Maintainers | mikesamuel |
| Keywords | container, lru-cache, cache, es6 |

## Links

- npm: https://www.npmjs.com/package/an-lru-cache
- Repository: https://github.com/mikesamuel/es6-lru-cache
- Homepage: https://github.com/mikesamuel/es6-lru-cache#readme
- Issues: https://github.com/mikesamuel/es6-lru-cache/issues
- npm.io page: https://npm.io/package/an-lru-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.5 (latest) — 2018-06-11
- 1.0.4 — 2018-02-16
- 1.0.3 — 2018-02-15
- 1.0.2 — 2018-02-15

## README

# ES6 LRU Cache

A simple [LRU Cache](https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU), a
Map that has a maximum number of entries and which discards the least recently used
items first.

To install

```sh
$ npm install an-lru-cache
```

[![Coverage Status](https://coveralls.io/repos/github/mikesamuel/es6-lru-cache/badge.svg?branch=master)](https://coveralls.io/github/mikesamuel/es6-lru-cache?branch=master)
[![Build Status](https://travis-ci.org/mikesamuel/es6-lru-cache.svg?branch=master)](https://travis-ci.org/mikesamuel/es6-lru-cache)
[![Dependencies Status](https://david-dm.org/mikesamuel/es6-lru-cache/status.svg)](https://david-dm.org/mikesamuel/es6-lru-cache)
[![npm](https://img.shields.io/npm/v/an-lru-cache.svg)](https://www.npmjs.com/package/an-lru-cache)

## API

The API mirrors the builtin `Map` and `WeakMap` APIs but does not include iterators.

```js
const { LruCache } = require('an-lru-cache')

const myCache = new LruCache()  // Default capacity is 100

function foo(key, value) {
  myCache.set(key, value)
  // ...
  return myCache.get(key)
}

function bar(key) {
  if (myCache.has(key)) {
    // ...
  }
  myCache.delete(key)
}
```


### `.set(key, value)`

Associates *value* with *key* so that `.get(key)` returns *value*
until a subsequent `.set` or `.delete` with the same *key* or
eviction.

### `.get(key, fallbackValue=undefined)`

Returns the value associated with *key*, or the *fallbackValue* if supplied.

Gets may return the *fallbackValue* even if there was a value associated
with *key* if that entry was evicted to ensure that the number of entries
did not exceed the maximum allowed.

### `.delete(key, fallbackValue=undefined)`

Deletes any entry for the given *key* returning the previously associated
value if present or *fallbackValue* otherwise.

### `.has(key)`

True iff there is a value associated with `key`.

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