backport memoization from rails 3

This is the first time I've made any proposed changes to our rails branch, so I'm both clueless about the process as well as how to get it bootstrapped to test the changes locally.  @josh - does this seem a reasonable solution? I'll take a pass at testing it once I figure out how to get `rake test` to actually execute without error.