# lrucache

> LRU Cache for node.js/browser.

Latest version **1.0.3** (published 2017-07-05) · 0 weekly downloads

## Install

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

## 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.3 |
| Published | 2017-07-05 |
| First published | 2014-06-29 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Maintainers | zensh |
| Keywords | lru, cache, lru-cache, lrucache |

## Links

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

## 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.3 (latest) — 2017-07-05
- 1.0.2 — 2016-05-28
- 1.0.1 — 2016-04-04
- 1.0.0 — 2016-01-19
- 0.3.0 — 2015-08-23
- 0.2.0 — 2014-12-04
- 0.1.1 — 2014-06-29
- 0.1.0 — 2014-06-29

## README

# LRUCache

LRU Cache for node.js/browser.

[![NPM version][npm-image]][npm-url]
[![Build Status][travis-image]][travis-url]
[![Downloads][downloads-image]][downloads-url]

使用链表实现的 LRU 缓存。`get`、`set` 和 `update` 方法会更新 LRU 优先级。

## Install

**Node.js:**

```sh
npm install lrucache
```

**bower:**

```sh
bower install lrucache
```

**Browser:**

```html
<script src="/pathTo/lrucache.js"></script>
```

## API

```js
const LRUCache = require('lrucache')
```

### Class LRUCache([capacity])

+ `capacity`: : *Optional*, Type: `Number`, Default: `Number.MAX_SAFE_INTEGER`.

```js
const cache = LRUCache(100)
```

### LRUCache.prototype.get(key)

Return `value`.

```js
let a = cache.get('a')
```

### LRUCache.prototype.set(key, value)

Return `this`.

```js
cache.set('a', [1, 2, 3])
```

### LRUCache.prototype.update(key, fn)

Return `this`, It only run when key exists.

```js
cache.update('a', function (a) {
  a.push(4)
  return a
})
```

### LRUCache.prototype.remove(key)

Return `this`.

```js
cache.remove('a')
```

### LRUCache.prototype.removeAll(key)

Return `this`.

```js
cache.removeAll()
```

### LRUCache.prototype.keys()

Return a array of `keys`.

```js
cache.keys()
```

### LRUCache.prototype.has(key)

Return `true` or `false`.

```js
cache.has('a')
```

### LRUCache.prototype.staleKey()

Return the stalest `key` or `null`.

```js
let staleKey = cache.staleKey()
```

### LRUCache.prototype.popStale()

Return the stalest `data` or `null`.

```js
let staleDate = cache.popStale()
```

### LRUCache.prototype.info()

Return `info`.

```js
cache.info()
```

[npm-url]: https://npmjs.org/package/lrucache
[npm-image]: http://img.shields.io/npm/v/lrucache.svg

[travis-url]: https://travis-ci.org/zensh/lrucache
[travis-image]: http://img.shields.io/travis/zensh/lrucache.svg

[downloads-url]: https://npmjs.org/package/lrucache
[downloads-image]: http://img.shields.io/npm/dm/lrucache.svg?style=flat-square

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