Selective memoization