# least-recent

> A cache object that deletes the least-recently-used items

Latest version **1.0.3** (published 2023-08-15) · (MIT OR Apache-2.0) license · 0 weekly downloads

## Install

```sh
npm install least-recent
pnpm add least-recent
yarn add least-recent
bun add least-recent
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2023-08-15 |
| First published | 2023-08-14 |
| Weekly downloads | 0 |
| License | (MIT OR Apache-2.0) |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 1 |
| Unpacked size | 32.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Sergey Ukustov |
| Maintainers | ukstv |
| Keywords | lru, lru-cache, cache |

## Links

- npm: https://www.npmjs.com/package/least-recent
- Repository: https://github.com/ceramicnetwork/least-recent
- Issues: https://github.com/ceramicnetwork/least-recent/issues
- npm.io page: https://npm.io/package/least-recent

## Dependencies (1)

- [nanoevents](https://npm.io/package/nanoevents.md) ^8.0.0

## 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) — 2023-08-15
- 1.0.2 — 2023-08-14
- 1.0.1 — 2023-08-14
- 1.0.0 — 2023-08-14

## README

# least-recent

Provides an implementation of LRUCache. Effectively a fork of [LRUCache from Mnemonist](https://github.com/Yomguithereal/mnemonist/tree/master) with one additional feature.

`LRU` standing for _least recently used_, can be seen as a a fixed-capacity key-value store that will evict infrequent items when full and setting new keys.

For instance, if one creates a `LRUCache` with a capacity of `1000` and one inserts a thousand-and-first key, the cache will forget its least recently used key-value pair in order not to overflow the allocated memory.

This structure is very useful to cache the result of costly operations when one cannot afford to keep every result in memory and only want to keep the most frequent ones.

For more information, you can check [this](<https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_recently_used_(LRU)>) Wikipedia page.

```typescript
import { LRUCache } from "least-recent";
```

## Usage

The `LRUCache` takes a single argument to create: the desired capacity. You could also provide types for keys and values.

```typescript
const cache = new LRUCache(1000);
const stringCache = new LRUCache<string, string>(1000);
```

For available methods, please see [Mnemonist LRUCache documentation](https://yomguithereal.github.io/mnemonist/lru-cachehttps://yomguithereal.github.io/mnemonist/lru-cache)

The only difference from Mnemonist, is we emit an event (using [`nanoevents`](https://www.npmjs.com/package/nanoevents)) if an entry gets evicted.

```typescript
import { LRUCache } from "least-recent";
const cache = new LRUCache(1000);
cache.on("evicted", (key, value) => {
  console.log("evicted entry", key, value);
});
```

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