Memoization and the flyweight pattern