# @neumatter/object-cache

> Module for creating ObjectCaches that can be garbage collected.

Latest version **1.0.0** (published 2023-07-18) · 0 weekly downloads

## Install

```sh
npm install @neumatter/object-cache
pnpm add @neumatter/object-cache
yarn add @neumatter/object-cache
bun add @neumatter/object-cache
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-07-18 |
| First published | 2023-07-18 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Cal Young |
| Maintainers | clyng57 |
| Keywords | slots, internal slots, object, cache, object cache, slot map, nodejs, string, javascript, module, node, es6 |

## Links

- npm: https://www.npmjs.com/package/@neumatter/object-cache
- Repository: https://github.com/Clyng57/object-cache
- Homepage: https://github.com/Clyng57/object-cache#readme
- Issues: https://github.com/Clyng57/object-cache/issues
- npm.io page: https://npm.io/package/@neumatter/object-cache

## Dependencies (1)

- [@neumatter/safe-collections](https://npm.io/package/@neumatter/safe-collections.md) ^1.0.0

## 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.0 (latest) — 2023-07-18

## README

# ObjectCache
![plot](https://img.shields.io/npm/v/%40neumatter%2Fobject-cache?style=for-the-badge&labelColor=black)
![plot](https://img.shields.io/npm/dt/%40neumatter%2Fobject-cache?style=for-the-badge&labelColor=black)
[![JavaScript Style Guide](https://cdn.rawgit.com/standard/standard/master/badge.svg)](https://github.com/standard/standard)

Module for creating ObjectCaches that can be garbage collected.
The ObjectCache will delete the least-recently-used entry to make room for new entries.

<br />

## Table of Contents
- [ Installation ](#install)
- [ Usage ](#usage)

<br />

<a name="install"></a>
## Install

```console
npm i @neumatter/object-cache
```

<br />

<a name="usage"></a>
## Usage

```js
import ObjectCache from '@neumatter/object-cache'

class CustomObject {
  constructor () {}

  get () {
    const objectCache = ObjectCache.from(this, { maxSize })
    let value = objectCache.get('key')

    if (value === undefined) {
      value = someExpensiveOp()
      objectCache.set('key', value)
    }

    return value
  }
}
```

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