# pessimism

> A fast HAMT Map intended for KV caching and optimistic updates

Latest version **1.1.4** (published 2019-09-18) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.4 |
| Published | 2019-09-18 |
| First published | 2019-08-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 94.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 15 |
| Author | Phil Pluckthun |
| Maintainers | philpl |
| Keywords | hamt, kv, cache, optimistic |

## Links

- npm: https://www.npmjs.com/package/pessimism
- Repository: https://github.com/kitten/pessimism
- Issues: https://github.com/kitten/pessimism/issues
- npm.io page: https://npm.io/package/pessimism

## 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.4 (latest) — 2019-09-18
- 1.1.3-fix-circular-remove (next) — 2019-09-17
- 1.1.3 — 2019-09-16
- 1.1.2 — 2019-09-13
- 1.1.1 — 2019-08-28
- 1.1.0 — 2019-08-27
- 1.0.1 — 2019-08-15
- 1.0.0 — 2019-08-14

## README

<h2 align="center">pessimism</h2>
<p align="center">
<strong>A fast and compact HAMT-based KV-Cache with optimistic entries</strong>
</p>

`pessimism` is a fast and compact KV-Cache primarily built for `@urql/exchange-graphcache`.
It's a functional and immutable HAMT structure, which increases structural sharing, while
keeping memory usage compact. It supports optimistic entries, which can be invalidated in a single go.

## Usage

This library works with both TypeScript and BuckleScript (Reason/OCaml).

```sh
yarn add pessimism
# or
npm install --save pessimism
```

The basic methods support making a map and setting, getting, and removing entries:

```js
import * as Map from 'pessimism';

let map = Map.set(Map.make(), "key", "value");
Map.get(map, "key"); // "value"

map = Map.remove(map, "key");
Map.get(map, "key"); // undefined
```

Optimistic entries can be set using `setOptimistic` and cleared using `clearOptimistic`:

```js
import * as Map from 'pessimism';

let map = Map.set(Map.make(), "key", "value");
// Set an optimistic entry with the ID 1
map = Map.setOptimistic("key", "temp", 1);

Map.get(map, "key"); // "temp" which is the optimistic value

// Clear all optimistic entries with ID 1
map = Map.clearOptimistic(map, 1);
Map.get(map, "key"); // "value" which was the original value
```

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