Caching evaluated result in rails helper methods
ruby-on-rails, ruby-on-rails-3
Solution
Sometimes I use Rails cache to store this kind of values. The code is like this,
def helper_method
Rails.cache.fetch('helper_value') do
# calculate the value if it does not exist
...
end
end
Problem
When implementing some helper methods, sometimes, I want to store some computed result somewhere accessible from the helper method as a cache. If I store it into instance variable, it will pollute instances, so it looks like not wise to do that. Any good place to store such value? Or doing such heavy weight computing in a helper is a bad idea?