Rails cache expire at midnight every day
There isn't an expires_at
option, but you can quickly calculate the number of seconds between your desired expiration time and the current time. Assuming you mean "expire at the end of the day tomorrow", you could do something like this:
expires_in_seconds = Time.now.end_of_day + 1.day - Time.now
Rails.cache.fetch("id...", expires_in: expires_in_seconds) do
#...
end
Where expires_in_seconds
would return a number of seconds (e.g. 90559
)
If you just mean "end of today", it would be Time.now.end_of_day - Time.now
.