# @ddatabase/cache

> A caching module for dDatabase tree nodes and blocks

Latest version **1.0.2** (published 2021-03-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install @ddatabase/cache
pnpm add @ddatabase/cache
yarn add @ddatabase/cache
bun add @ddatabase/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 | 2021-03-25 |
| First published | 2021-03-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | PeepsLabs |
| Maintainers | dwebprotocol |
| Keywords | ddatabase, cache |

## Links

- npm: https://www.npmjs.com/package/@ddatabase/cache
- Repository: https://github.com/dwebprotocol/ddatabase-cache
- Homepage: https://dwebx.org
- Issues: https://github.com/dwebprotocol/ddatabase-cache/issues
- npm.io page: https://npm.io/package/@ddatabase/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) — 2021-03-25
- 1.0.1 — 2021-03-10
- 1.0.0 — 2021-03-05

## README

# @ddatabase/cache


A caching module for dDatabase 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 @ddatabase/cache --save
```

### API

#### `const cache = new DDatabaseCache(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 @ddatabase/cache API.

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

### License
MIT

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