Understanding the memoization design pattern