Simple decorator for caching the result of a function based on the most recent arguments.
npm install decorator-memoize-one --save
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);
MIT