-
Notifications
You must be signed in to change notification settings - Fork 21.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Skip the :race_condition_ttl
branch if the option is 0 or nil.
#19296
Conversation
… fixes an issue with the redis cache, where this code will sometimes throw an error out of SETEX when passing 0 as the `expires_at`.
@@ -566,8 +566,8 @@ def find_cached_entry(key, name, options) | |||
def handle_expired_entry(entry, key, options) | |||
if entry && entry.expired? | |||
race_ttl = options[:race_condition_ttl].to_i | |||
if race_ttl && (Time.now.to_f - entry.expires_at <= race_ttl) | |||
# When an entry has :race_condition_ttl defined, put the stale entry back into the cache | |||
if (race_ttl > 0) && (Time.now.to_f - entry.expires_at <= race_ttl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if race_ttl
is nil
it will now raise a NoMethodError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
race_ttl = options[:race_condition_ttl].to_i
will never be nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup! nil.to_i
evaluates to 0
and 0
is truthy in ruby.
ttl = nil.to_i
puts ttl
if ttl
puts "I am a tautology."
end
Outputs
0
I am a tautology.
@rafaelfranca @egilburg Ping. Is there anything I need to do here? |
@Wildebeest no it's ok. I know 0 is truthy, I just didn't realize the old code already checked for it (meaning the old code before your patch didn't actually check anything meaningful, because essentially it always checked |
Sweet. Thanks! :) |
Skip the `:race_condition_ttl` branch if the option is 0 or nil.
Skip the `:race_condition_ttl` branch if the option is 0 or nil.
Skip the `:race_condition_ttl` branch if the option is 0 or nil.
This fixes an issue with the redis cache, where this code will sometimes throw an error out of SETEX when passing 0 as the
expires_at
.