# @mdxvac/mem-cache

> Typed memory cache for stateless functions

Latest version **0.0.4** (published 2022-10-11) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @mdxvac/mem-cache
pnpm add @mdxvac/mem-cache
yarn add @mdxvac/mem-cache
bun add @mdxvac/mem-cache
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2022-10-11 |
| First published | 2022-09-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 3.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | christian@hackyourshack.org |
| Maintainers | shackhacker-christian |
| Keywords | utilities, cache, typescript |

## Links

- npm: https://www.npmjs.com/package/@mdxvac/mem-cache
- Repository: https://github.com/mdxvac/mdxvac.git#main
- Homepage: https://mdxvac.netlify.app/
- Issues: https://github.com/mdxvac/mdxvac/issues
- npm.io page: https://npm.io/package/@mdxvac/mem-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

- 0.0.4 (latest) — 2022-10-11
- 0.0.3 — 2022-09-23
- 0.0.2 — 2022-09-22
- 0.0.1 — 2022-09-20

## README

# @mdxvac/mem-cache

> **DEPRECATED:** Please consider using the plugin [astro-m2dx](https://www.npmjs.com/package/astro-m2dx), which bundles all features from the `@mdxvac` plugins in one plugin (completely opt-in).

Simple typed in-memory cache for stateless functions.

## Content

- [Content](#content)
- [What is this?](#what-is-this)
- [When should I use this?](#when-should-i-use-this)
- [Install](#install)
- [Use](#use)

## What is this?

This package is a simple TypeScript class, that allows to wrap a stateless function in a cache.

## When should I use this?

If you have a computation-intensive or I/O-heavy (quasi) stateless function, that will return the same value for each invocation with the same parameters, then you can wrap it into this cache and use cached values for repeated calls.

> I use it e.g. in a Static Site Generator to access values from configuration files.

## Install

```sh
npm install -D @mdxvac/mem-cache
```

## Use

```js
function expensiveComputation(a: string, b: number) {
  return `${a} - ${b}`;
}
const cachedComputation = new MemCache(expensiveComputation);

const result = cachedComputation.get('a', 8);
```

Of course, you can also use arrow functions to initialize the cache:

```js
const cachedComputation = new MemCache((a: string, b: number): string => {
  return `${a} - ${b}`;
});
```

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