cache / cachify
cache and cachify are aliases for memoize. They create a cached version of an async function, storing results by argument key.
See
memoizefor full documentation.
Import
Section titled “Import”Root package:
import { cache, cachify } from "@vgerbot/async";Module subpath:
import { cache, cachify } from "@vgerbot/async/utils";Leaf subpath:
import { cache } from "@vgerbot/async/utils/cache";Quick example
Section titled “Quick example”import { cache } from "@vgerbot/async";
const fetchUser = cache(async (userId: string, token) => { const res = await token.wrap(fetch(`/api/users/${userId}`)); return res.json();});
// First call fetchesconst user1 = await fetchUser("123").promise;
// Second call returns cached resultconst user2 = await fetchUser("123").promise;
console.log(user1 === user2); // true