# @byungi/lru-cache

> Typed fast LRU cache for browser.

Latest version **0.1.1** (published 2019-10-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install @byungi/lru-cache
pnpm add @byungi/lru-cache
yarn add @byungi/lru-cache
bun add @byungi/lru-cache
```

## Health

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

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

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2019-10-31 |
| First published | 2019-10-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | skt-t1-byungi |
| Maintainers | skt-t1-byungi |
| Keywords | lru, cache, ttl, time to live |

## Links

- npm: https://www.npmjs.com/package/@byungi/lru-cache
- Repository: https://github.com/skt-t1-byungi/lru-cache
- npm.io page: https://npm.io/package/@byungi/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

- 0.1.1 (latest) — 2019-10-31
- 0.1.0 — 2019-10-31
- 0.0.2 — 2019-10-28
- 0.0.1 — 2019-10-28

## README

# @byungi/lru-cache
> Typed fast LRU cache for browser.

Implemented by the fast lru algorithm of [hashlru](https://github.com/dominictarr/hashlru).
Added [ttl](https://en.wikipedia.org/wiki/Time_to_live) and old browser support.


[![npm](https://flat.badgen.net/npm/v/@byungi/lru-cache)](https://www.npmjs.com/package/@byungi/lru-cache)
[![license](https://flat.badgen.net/github/license/skt-t1-byungi/lru-cache)](https://github.com/skt-t1-byungi/lru-cache/blob/master/LICENSE)

## Install
```sh
npm i @byungi/lru-cache
```

## Example
```js
import LRUCache from '@byungi/lru-cache'

const cache = new LRUCache({max: 2, ttl: 100})

cache.set('a', 1)
console.log(cache.has('a')) // => true

cache.set('b', 2)
cache.set('c', 3)
cache.set('d', 4)
console.log(cache.has('a')) // => false

console.log(cache.has('d')) // => true
setTimeout(()=> {
    // After ttl(100ms).
    console.log(cache.has('d')) // => false
}, 100)
```

## API
### new LRUCache(options?)
Create an instance.

#### options
- `max` - Maximum cache size. (Default: `Infinity`)
- `ttl` - Time to live. (Default: `Infinity`)
- `renewTTL` - If `true`, renew `ttl` when getting value. (Default: `true`)

### cache.set(key, value)
Set value by key.

### cache.get(key)
Get value by key.

### cache.has(key)
Returns whether a key exists.

### cache.delete(key)
Delete value by key

### cache.clear()
Delete all values.

## License
MIT

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