Is there a way to do something like
Rails.cache.fetch("id..", expire_in: 1.day, expire_at: midnight) do
#...
end
thanks!
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With