Allow for optional memoization (mainly for testing).