I have a long database query in one of our dashboard systems that I would like to cache, since the results do not have to be accurate in real time, but they can give a value "close enough" from the cache.
I would like to do this without having to wait for the user. I was looking at using something like
Rails.cache.write('my_val', 'val', :expires_in => 60.minutes)
to keep this value, but I do not believe that it gives the exact functionality that I want. I would like to call using
Rails.fetch('my_val') { create a background task to update my_val; return expired my_val}
It seems that my_val is being removed from the cache when it expired. Is there a way to access this expired value, or perhaps another inline mechanism that would enable this functionality?
Thanks.
source share