Skip to Content
The Public InterfaceSeptember 12, 2026

The Public Interface

November 12, 2025

Simple Memoization in TypeScript

A tiny class to memoize a function in TS.

By Ross Robinomemo / cache / javascript

JavaScript isn’t the fastest language, it’s best to make sure repeated async operations and expensive computations aren’t done repeatedly. Here’s a Memo class that ensures whether it be an async function that has latency, or an expensive mathematical computation, the same operations are not running multiple times.

This memo class creates a trie for each function using each argument it is called with. Async calls link to the same result so they are not called twice even if the async call hasn’t completed yet!

If you are memoizing on a web server, be sure to create the memo instance within the scope of the request or in AsyncLocalStorage if you are caching sensitive data.…

Continue reading