3 ms·
There is a subtle difference though. With general caching you have to worry about stale data. Since memoization applies to pure functions where a given input al
by noblethrasher 15y ago
There is a subtle difference though. With general caching you have to worry about stale data. Since memoization applies to pure functions where a given input always results in the same output, "cache invalidation" isn't much of an issue.
- vannevar 15y agoFTA: "Memoization is a computer science concept to optimize programs by avoiding computations that have already been done and to reuse it. This is achieved by storing the computaions in a lookup table and retrieving them if a need for it arrives in a future computation step." From Wikipedia: "In computer engineering, a cache (/ˈkæʃ/ kash[1]) is a component that transparently stores data so that future requests for that data can be served faster. The data that is stored within a cache might be values that have been computed earlier or duplicates of original values that are stored elsewhere. If requested data is contained in the cache (cache hit), this request can be served by simply reading the cache, which is comparatively faster." (Emphasis mine.)
- noblethrasher 15y agoYou're right that memoization is a subset of caching but it still warrants special attention because every pure function gets to have a .Memoize() "method" for free. This isn't true for caching in general.
- vannevar 15y agoAnd a red car is a subset of all cars, but we don't make up a special term for it. Many caching techniques have implementation details that distinguish them from one another, but we nonetheless refer to them by the same term. Caching from a database is different from caching in a CPU, but the basic mechanism and purpose is the same so we use the same term for clarity. I've never seen an article on memoization that couldn't be made more clear by substituting 'caching' wherever it used 'memoization'.