liveBook · Manning

Caching

As explained in Functional Programming in JavaScript

An intermediary repository that stores previously computed or retrieved values for later reuse.

Caching avoids repeating expensive computations by storing each result under a key and returning it when the same input appears again. A cache sits between a function call and its expensive operation, serving as an intermediary repository for reusable values. section 7.3

Memoization applies this idea to functions: arguments generate a unique key, the first call computes and stores the result, and later calls with the same arguments produce a cache hit. Referential transparency makes this reuse reliable. section 7.3

Memoizing a repeated computation

Memoized ROT13 computes the discount code once: the first run takes about 0.733 ms, while the second takes about 0.021 ms. Memoized student lookup similarly reduces repeated composed processing from about 9.2 ms to 2.5 ms.

How Functional Programming in JavaScript covers it

How deep it goes
Explains cache keys, hits, misses, wrappers, and performance effects, but does not detail cache eviction or invalidation.
Examples
Uses cached student lookup, memoized ROT13, composed student display, and recursive factorial examples.
What it assumes
Assumes familiarity with JavaScript functions, arguments, function calls, and basic functional composition.
What you can do after
Apply memoization to reduce repeated computation in JavaScript functions.
How it connects
Connects caching with memoization, referential transparency, pure functions, currying, composition, and functional languages.

Also explained in

Compare how 38 books explain caching →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in JavaScript. The section links point to the parts of the book it draws on.