Skip to content

FAQ

Frequent questions about memoization: how it differs from caching, its risk, and how to implement it.

Memoization vs caching?

Memoization is a function-level cache keyed by arguments. General caching is usually external (Redis, CDN) and time-based.

What is the biggest risk?

Memory leaks. An unbounded memo dict in a long-running process will grow until OOM.

When to use it?

Pure functions that are expensive to compute and called repeatedly with the same arguments.

Can it be async?

Yes, by caching the Promise. But if the Promise rejects, you must clear the cache or you will cache the failure.