Add memoization for getattr