Does anyone know why rails seems to recalculate the value of "expires_in" each time a cached fragment is read?
EXAMPLE
cache("usecase_#{usecase.id}", :expires_in => "#{usecase.minutesToNextRun}".to_i.minutes) do
some code
end
If I check the logs I see that the usecase.minutesToNextRun
method is called each time the cache fragment is read (which is quite expensive and slows down the app).
THEORY
Normally I'd expect rails to just calculate the :expires_in
value once and then just compare this value (e.g. 5 minutes) to the current time (in pseudocode).
if time_the_fragment_was_stored + expires_in > now
do nothing
else
re-render fragment
end
QUESTION
Does anyone have any hint/idea how I can prevent rails from recalculating the expiry time each time the fragment is read?