Comparing the terms “memoize” and “cache” and in reading Wikipedia’s memoization entry, do people agree that using the term “memoize” implies
- The memoized result is kept in the process’ memory; in other words, it isn’t stored in memcached .
- One only “memoizes” functions, as in mathematical functions, e.g. Fibonacci, not values that may change over time, e.g. the number of registered users on the web site?
If you’re doing anything else than the above, then one is just caching a result?
I believe that memoizing a function allows you to locally cache the result of a function for a given set of arguments. It’s almost like:
but with the initial huge “if” block being handled automatically and far more efficiently, and being added to as the function is called with different arguments.
Note that you can only memoize a function that is deterministic and has no side effects. This means that the function’s result can only depend on its inputs, and it cannot change anything when it is run.
So in short, memoization is function-local caching in very specific circumstances, and so it’s a specialisation of regular caching.