# hypercore-cache

> A caching module for Hypercore tree nodes and blocks

Latest version **1.0.2** (published 2020-02-03) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2020-02-03 |
| First published | 2020-02-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Andrew Osheroff |
| Maintainers | andrewosh |
| Keywords | hypercore, cache |

## Links

- npm: https://www.npmjs.com/package/hypercore-cache
- Repository: https://github.com/andrewosh/hypercore-cache
- Homepage: https://github.com/andrewosh/hypercore-cache#readme
- Issues: https://github.com/andrewosh/hypercore-cache/issues
- npm.io page: https://npm.io/package/hypercore-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.0.2 (latest) — 2020-02-03
- 1.0.1 — 2020-02-03
- 1.0.0 — 2020-02-03

## README

# hypercore-cache
[![Build Status](https://travis-ci.com/andrewosh/hypercore-cache.svg?token=WgJmQm3Kc6qzq1pzYrkx&branch=master)](https://travis-ci.com/andrewosh/hypercore-cache)

A caching module for Hypercore tree nodes and blocks.

This module mplements the [hashlru](https://github.com/dominictarr/hashlru) algorithm internally for LRU caching, but it uses byte length estimates instead of the entry count for eviction.

### Installation
```
npm i hypercore-cache --save
```

### API

#### `const cache = new HypercoreCache(opts = {})`
Creates a new cache.

Options can include:
```js
{
  maxByteSize: 1e6,  // The soft maximum size of the cache (actual max size can go up to 2x this value).
  estimateSize: val => { ... },  // A function from a value to its size estimate.
  onEvict: (evicted) => { ... }  // A hook that's called when stale entries (a Map) have been evicted.
}
```

#### `cache.set(key, value)`
Sets `key` to `value`.

#### `cache.get(key)`
Gets the value for `key`.

#### `cache.del(key)`
Deletes `key` from the cache.

#### `const subCache = cache.namespace()`
Creates a namespaced sub-cache which mirrors the hypercore-cache API.

This is useful if you want to create a single cache instance that manages resources for multiple hypercores.

### License
MIT

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