# pythagorean-cache

> A cache that empties when full or at an interval

Latest version **1.0.1** (published 2026-01-02) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 55/100 (C)** — status: stable.

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

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2026-01-02 |
| First published | 2019-04-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 15.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Shaun Burdick |
| Maintainers | shaunburdick |
| Keywords | cache, interval, pythagorean, dump |

## Links

- npm: https://www.npmjs.com/package/pythagorean-cache
- Repository: https://github.com/shaunburdick/pythagorean-cache
- Homepage: https://github.com/shaunburdick/pythagorean-cache#readme
- Issues: https://github.com/shaunburdick/pythagorean-cache/issues
- npm.io page: https://npm.io/package/pythagorean-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.1 (latest) — 2026-01-02
- 1.0.0 — 2019-04-25

## README

# Pythagorean Cache

[![npm version](https://badge.fury.io/js/pythagorean-cache.svg)](https://badge.fury.io/js/pythagorean-cache)  [![Build Status](https://github.com/shaunburdick/pythagorean-cache/actions/workflows/test.yml/badge.svg)](https://github.com/shaunburdick/pythagorean-cache/actions/workflows/test.yml)

🍷A cache that dumps when full or at an interval

[![cup](https://upload.wikimedia.org/wikipedia/commons/a/a9/Physagorian_Pythagoras_Greedy_Tantalus_cup_05.svg)](https://en.wikipedia.org/wiki/Pythagorean_cup)

## Example

```typescript
import { PythagoreanCache } from 'pythagorean-cache';

// dump when size reaches 10
const cache = new PythagoreanCache<string>({ size: 10 });

cache.on('dump', () => {
  /* do something with 10 items */
});

for (let x = 0; x < 10; x++) {
  cache.push(`Hello ${x}`);
}
```

## Options

- size: The size of the cache. When the size is reached, a `dump` event is fired with all the items in the cache and then emptied
- interval: The number of microseconds to wait before firing a `dump` event. This can be used to dump the cache at regular intervals.

These options can be combined, allowing you to create a cache that dumps at a certain size _or_ at a certain interval.

## Inspired Use Case

I was receiving a bursting stream of events I needed to add to a database. Instead of inserting each one as they come in, it was more efficient to do bulk inserts at intervals/sizes. This way that database was protected from burst events and I could expect the events to be inserted within a certain amount of time regardless.

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