Properly memoize protected methods

This patch fixes an issue with protected methods becoming public if
they are memoized.

Looking for +1's and/or a commit by core...

https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/5695

Thanks.

Now added a patch for 2.3.x along with the original patch for 3.x.