# node-inmemory

> A simple in-memory cache system for node.js.

Latest version **0.1.1** (published 2023-05-15) · 0 weekly downloads

## Install

```sh
npm install node-inmemory
pnpm add node-inmemory
yarn add node-inmemory
bun add node-inmemory
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2023-05-15 |
| First published | 2023-01-04 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 18 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | joyqi |
| Maintainers | joyqi |

## Links

- npm: https://www.npmjs.com/package/node-inmemory
- Repository: https://github.com/joyqi/node-inmemory
- Homepage: https://github.com/joyqi/node-inmemory#readme
- Issues: https://github.com/joyqi/node-inmemory/issues
- npm.io page: https://npm.io/package/node-inmemory

## Recent versions

- 0.1.1 (latest) — 2023-05-15
- 0.1.0 — 2023-01-04

## README

# node-inmemory

A simple in-memory cache for node.js. Create a new cache with a given ttl (time to live) and a callback function to be called when the cache expires.

## Installation

```bash
npm install node-inmemory
```

## Usage

```javascript
const { inMemory } = require('node-inmemory');

const [get, reset] = inMemory(() => {
  console.log('Cache initialized');
  return 'Hello World';
}, 1000);

console.log(get()); // Cache initialized \n Hello World
reset();
console.log(get()); // Cache initialized \n Hello World

setTimeout(() => {
  console.log(get()); // Cache initialized \n Hello World
}, 2000);
```

Async functions are also supported:

```javascript
const { inMemory } = require('node-inmemory');

const [get, reset] = inMemory(async () => {
  console.log('Cache initialized');
  return 'Hello World';
}, 1000);

console.log(await get()); // Cache initialized \n Hello World
```

Set ttl to 0 (default) to disable the expiration:

```javascript
const { inMemory } = require('node-inmemory');

const [get, reset] = inMemory(() => {
  console.log('Cache initialized');
  return 'Hello World';
});

console.log(get()); // Cache initialized \n Hello World

setTimeout(() => {
  console.log(get()); // Hello World
}, 2000);
```

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