# mini-lru-cache

> A simple Least Recently Used (LRU) Cache for node.js

Latest version **0.0.2** (published 2021-10-09) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2021-10-09 |
| First published | 2021-10-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | kapeter |
| Maintainers | kapeter |

## Links

- npm: https://www.npmjs.com/package/mini-lru-cache
- Repository: https://github.com/kapeter/mini-lru-cache
- Homepage: https://github.com/kapeter/mini-lru-cache#readme
- Issues: https://github.com/kapeter/mini-lru-cache/issues
- npm.io page: https://npm.io/package/mini-lru-cache

## Recent versions

- 0.0.2 (latest) — 2021-10-09
- 0.0.1 — 2021-10-09

## README

# mini-lru-cache

A simple Least Recently Used (LRU) Cache for node.js

## Installation

```
npm install mini-lru-cache --save
```

## Usage

```javascript
const cache = require('mini-lru-cache');

cache.put('name', 'bob');
console.log(cache.get('name')); // 'bob'
cache.del('name');
console.log(cache.get('name')); // null

cache.put('name', 'bob');
cache.put('age', '43');
console.log(cache.get('name')); // 'bob'
console.log(cache.get('age')); // '43'
console.log(cache.size()); // 2
cache.clear();
console.log(cache.get('name')); // null
console.log(cache.get('age')); // null
console.log(cache.size()); // 0
```

## API

### put(key: any, value: any, time: NULL | number)

Stores a value，If time isn't passed in, it is stored forever, Returns the cached value

### get(key: any)

Retrieves a value for a given key，If value isn't cached, returns `null`

### del(key: any)

Deletes a key

### clear()

Deletes all keys

### size()

Returns the current number of entries in the cache

### changeMaxSize(size: number)

Change the max number of entries in the cache, default: os.freemem() / 1024 / 2 / 10

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