# cachimo

> Stores key with value in-memory and can be deleted manually or after given timeout.

Latest version **2.0.4** (published 2020-07-07) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

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

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2020-07-07 |
| First published | 2018-02-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | svipas |
| Maintainers | svipas |
| Keywords | cache, in-memory, storage, nodejs, browser |

## Links

- npm: https://www.npmjs.com/package/cachimo
- Repository: https://github.com/svipben/cachimo
- Homepage: https://github.com/svipas/cachimo
- Issues: https://github.com/svipas/cachimo/issues
- npm.io page: https://npm.io/package/cachimo

## 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

- 2.0.4 (latest) — 2020-07-07
- 2.0.3 — 2020-06-25
- 2.0.2 — 2020-05-17
- 2.0.1 — 2020-05-02
- 2.0.0 — 2020-05-02
- 1.0.7 — 2019-08-03
- 1.0.6 — 2018-04-15
- 1.0.5 — 2018-03-10
- 1.0.4 — 2018-02-17
- 1.0.3 — 2018-02-17
- 1.0.2 — 2018-02-07
- 1.0.1 — 2018-02-01
- 1.0.0 — 2018-02-01

## README

# cachimo &middot; [![npm](https://img.shields.io/npm/v/cachimo.svg)](https://www.npmjs.com/package/cachimo) [![Build Status](https://dev.azure.com/svipas/svipas/_apis/build/status/svipas.cachimo?branchName=master)](https://dev.azure.com/svipas/svipas/_build/latest?definitionId=6&branchName=master)

Stores key with value in-memory and can be deleted manually or after given timeout.

## Installation

### npm

```
npm install cachimo
```

### Yarn

```
yarn add cachimo
```

## Usage

### API

- **put**

```ts
import * as cachimo from "cachimo";

// Stores element in cache, you can remove it manually whenever you want.
// Returns true if element was successfully stored in cache, false if such key already exist.
cachimo.put("key", "value");
```

```ts
import * as cachimo from "cachimo";

// Stores element in cache and it will be deleted after given timeout which returns Promise.
cachimo
	.put("key", "value", 1000) // It will be deleted after 1 sec. and Promise will be resolved or rejected.
	.then(({ key, value, timeout }) => {
		// Returns key, value and timeout after delete.
		console.log(`Deleted ${key}:${value} after ${timeout}`);
	})
	.catch((err) => {
		// You will get error if key was deleted before timeout.
		throw err; // "Key doesn't exist."
	});
```

```ts
import * as cachimo from "cachimo";

// If you don't want to use Promise you can send callback which will be executed after given timeout.
cachimo.put("key", "value", 1000, (err, key, value, timeout) => {
	// You will get error if key was deleted before timeout.
	if (err) {
		throw err; // "Key doesn't exist."
	}

	// Returns key, value and timeout after delete.
	console.log(`Deleted ${key}:${value} after ${timeout}`);
});
```

- **clear**

```ts
import * as cachimo from "cachimo";

// Removes all elements stored in cache and clears all timeouts.
// Returns number of how much elements was removed from cache.
cachimo.clear();
```

- **get**

```ts
import * as cachimo from "cachimo";

// Returns value from cache by given key.
cachimo.get("key");
```

- **remove**

```ts
import * as cachimo from "cachimo";

// Returns true if element was removed, false otherwise.
cachimo.remove("key");
```

- **has**

```ts
import * as cachimo from "cachimo";

// Checks if whether an element with given key exists.
// Returns true if element exists, false otherwise.
cachimo.has("key");
```

- **size**

```ts
import * as cachimo from "cachimo";

// Returns the number of elements stored in cache.
cachimo.size();
```

- **keys**

```ts
import * as cachimo from "cachimo";

// Returns all keys stored in cache.
cachimo.keys();
```

- **values**

```ts
import * as cachimo from "cachimo";

// Returns all values stored in cache.
cachimo.values();
```

- **entries**

```ts
import * as cachimo from "cachimo";

// Returns all entries (keys and values) stored in cache.
cachimo.entries();
```

## Contributing

Feel free to open issues or PRs!

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