This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

@mdxvac/mem-cache
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

@mdxvac/mem-cache

DEPRECATED: Please consider using the plugin 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

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

npm install -D @mdxvac/mem-cache

Use

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:

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

Package Sidebar

Install

npm i @mdxvac/mem-cache

Weekly Downloads

0

Version

0.0.4

License

MIT

Unpacked Size

3.91 kB

Total Files

4

Last publish

Collaborators

  • shackhacker-christian