/decorator-memoize-one

Simple decorator for caching the result of a function based on the most recent arguments

Primary LanguageTypeScriptMIT LicenseMIT

Decorator Memoize One

NPM version NPM downloads Build status Test coverage

Simple decorator for caching the result of a function based on the most recent arguments.

Installation

npm install decorator-memoize-one --save

Usage

import { memoizeOne } from "decorator-memoize-one";
import { pool } from "./db";

class User {
  @memoizeOne
  friends(pool) {
    return pool.execute("SELECT * FROM users WHERE ...");
  }
}

const user = new User();
const friends = await user.friends(pool);

License

MIT