I'm writing a Rails app and I have a variable whose value takes a significant time to calculate. The variable must be re-calculated at the beginning of each request.
If possible, I'd like to access this variable from different model classes but I'll settle for one calculation per model.
EDIT: e.g. something like this:
module MyHelper
def get_my_var
@@my_var ||= some_expensive_calculation
end
end
So that I can call get_my_var
from any controller or model. The only caveat is that I want @@my_var
to be recalculated on every request.
Any ideas?