Memoization with optional fading memory.