Comparison
MemoisationvsPure function
Memoisation
you cache the return value of a pure function inside the process so calling it twice with the same arguments only computes once.
In-process caching keyed on a function's arguments, valid only where the function is genuinely pure. It is the cheapest caching there is, with no network hop and no serialisation. It is also invisible to your invalidation story: memoised values live until the process dies, which is why it belongs on computation, not on anything that reads state.
Full entry →Pure function
you called it twice with the same arguments, got the same answer, and nothing anywhere else changed.
A function whose result depends only on its arguments and which changes nothing outside itself. Purity is what makes a function trivially testable, safely cacheable, freely reorderable and safe to run on several threads — every one of those properties follows from the same two conditions. The design move it suggests is not writing everything this way but knowing which of your functions are, and being deliberate about where the impure ones live.
Full entry →