# slim-cache

> Super Fast Lightweight Cache with a Map like interface

Latest version **1.1.1** (published 2019-07-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install slim-cache
pnpm add slim-cache
yarn add slim-cache
bun add slim-cache
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2019-07-11 |
| First published | 2019-07-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8 |
| Dependencies | 0 |
| Unpacked size | 17.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Nivrith |
| Maintainers | nivrith |
| Keywords | cache, memoize, caching, perf, performance, optimizations, optimize, slim-cache, fast-cache |

## Links

- npm: https://www.npmjs.com/package/slim-cache
- Repository: https://github.com/nivrith/slim-cache
- npm.io page: https://npm.io/package/slim-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.1.1 (latest) — 2019-07-11
- 1.1.0 — 2019-07-10
- 1.0.0 — 2019-07-09

## README

# slim-cache

[![CircleCI](https://circleci.com/gh/nivrith/slim-cache/tree/master.svg?style=svg)](https://circleci.com/gh/nivrith/slim-cache/tree/master)
[![NPM Downloads](https://img.shields.io/npm/dw/slim-cache.svg)](https://www.npmjs.com/package/slim-cache)
[![node](https://img.shields.io/node/v/slim-cache.svg)](https://www.npmjs.com/package/slim-cache)
[![License MIT](https://img.shields.io/github/license/nivrith/slim-cache.svg)](https://github.com/nivrith/slim-cache/blob/master/LICENSE)

Super Fast Lightweight Cache with a Map like interface

## Highlights

- Super Fast

- Written in Typescript

- Easy Map Like Interface

## Usage

> Super Fast Lightweight Cache with a Map like interface

```js

  import SlimCache from 'slim-cache';

  cache = new SlimCache(); // creates new cache
  cache.set('hello', 'world');
  cache.get('hello'); // 'world'
  cache.has('hello'); // true
  cache.clear('hello'); //true
  cache.isEmpty(); // true
  cache.set('hello', 'world');
  cache.clean(); // Clears every key of the cache rendering it empty
  cache.isEmpty(); // true
  cache.flush({'new': 'cache'}); // replaces internal cache object with user provided object
  cache.get('new'); // cache
```

## Benchmark

All benchmarks were run using [benchmark](https://www.npmjs.com/package/benchmark)

### Memoization

[fast-memoize](https://npmjs.com/package/fast-memoize) was used with various caches to memoize
a standard recursive fibonacci function

Benchmark was run for all the memoized functions to find 40th fibonacci number

``` js

┌──────────────┬─────────────┬──────────────────────────┬─────────────┐
│ NAME         │ OPS/SEC     │ RELATIVE MARGIN OF ERROR │ SAMPLE SIZE │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ slim-cache   │ 402,727,692 │ ± 0.35%                  │ 93          │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ object cache │ 391,995,589 │ ± 0.61%                  │ 94          │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ map-cache    │ 388,972,451 │ ± 1.58%                  │ 92          │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ fast-memoize │ 334,922,846 │ ± 0.35%                  │ 91          │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ native map   │ 265,225,627 │ ± 0.56%                  │ 90          │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ vanilla      │ 1           │ ± 6.91%                  │ 7           │
└──────────────┴─────────────┴──────────────────────────┴─────────────┘
```

#### Legend

- slim-cache : fibonacci function memoized using fast-memoize with SlimCache instance

- object cache: fibonacci function memoized using fast-memoize with Empty Object based cache

- map-cache: fibonacci function memoized using fast-memoize with [MapCache](https://npmjs.com/package/map-cache)
 instance

- fast-memoize: default fast-memoize cache

- native map: fibonacci function memoized using fast-memoize with Native ES6 Map based cache

- vanilla: fibonacci function without memoization

### Methods

#### has

```js
┌────────────┬─────────────┬──────────────────────────┬─────────────┐
│ NAME       │ OPS/SEC     │ RELATIVE MARGIN OF ERROR │ SAMPLE SIZE │
├────────────┼─────────────┼──────────────────────────┼─────────────┤
│ slim-cache │ 902,468,492 │ ± 1.63%                  │ 93          │
├────────────┼─────────────┼──────────────────────────┼─────────────┤
│ native map │ 694,384,457 │ ± 0.62%                  │ 95          │
├────────────┼─────────────┼──────────────────────────┼─────────────┤
│ map-cache  │ 686,595,656 │ ± 0.74%                  │ 90          │
├────────────┼─────────────┼──────────────────────────┼─────────────┤
│ object     │ 184,851,669 │ ± 3.27%                  │ 86          │
└────────────┴─────────────┴──────────────────────────┴─────────────┘
```

#### get

```js

┌────────────┬─────────────┬──────────────────────────┬─────────────┐
│ NAME       │ OPS/SEC     │ RELATIVE MARGIN OF ERROR │ SAMPLE SIZE │
├────────────┼─────────────┼──────────────────────────┼─────────────┤
│ slim-cache │ 917,775,700 │ ± 0.42%                  │ 94          │
├────────────┼─────────────┼──────────────────────────┼─────────────┤
│ map-cache  │ 914,493,164 │ ± 0.46%                  │ 92          │
├────────────┼─────────────┼──────────────────────────┼─────────────┤
│ object     │ 913,072,253 │ ± 0.54%                  │ 91          │
├────────────┼─────────────┼──────────────────────────┼─────────────┤
│ native map │ 667,015,102 │ ± 1.69%                  │ 91          │
└────────────┴─────────────┴──────────────────────────┴─────────────┘
```

### set

```js
┌──────────────┬─────────────┬──────────────────────────┬─────────────┐
│ NAME         │ OPS/SEC     │ RELATIVE MARGIN OF ERROR │ SAMPLE SIZE │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ object cache │ 916,023,083 │ ± 0.39%                  │ 96          │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ slim-cache   │ 912,787,773 │ ± 0.50%                  │ 94          │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ map-cache    │ 911,402,606 │ ± 0.56%                  │ 96          │
├──────────────┼─────────────┼──────────────────────────┼─────────────┤
│ native map   │ 144,171,162 │ ± 0.48%                  │ 91          │
└──────────────┴─────────────┴──────────────────────────┴─────────────┘

```

## License

MIT © [Nivrith Mandayam Gomatam](https://au.linkedin.com/in/nivrith-gomatam-43bb7aa5)

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