-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Fix forced cache miss for fetch. #24577
Conversation
Why are we adding |
@jeremy We are skipping I think I should move handling of ...
else
options && options[:force] ? nil : read(name, options)
end Let me know your thoughts. |
I see. That would make sense, yes. However, does this make sense overall? Forcing a cache miss only makes sense when a block is provided to write the new value. When no block is provided, fetch is a cache read where I think it'd make sense to raise an ArgumentError instead. Note, the docs show an example of calling |
36bfd10
to
7c63762
Compare
@jeremy Please check. I have raised an argument error if no block is passed to |
7c63762
to
f7842c2
Compare
else | ||
read(name, options) | ||
fetch_without_block(name, options) |
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.
I think we can get away without extracting separate implementation methods.
if block_given?
# fetch = write if not present
elsif options[:force]
raise ArgumentError, "…"
else
# read …
end
- Raised an argument error if no block is passed to #fetch with 'force: true' option is set. - Added tests for the same.
f7842c2
to
a712acc
Compare
@jeremy I updated the code as per your suggestions. |
Fix forced cache miss for fetch when called without a block.
Thanks, @jeremy 😃 |
As per given document, if we call fetch method with 'force: true' option without
the block, it should force a cache miss. But it was happening properly,
so added this fix.
https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache.rb#L200-L204
UPDATE
Based on the discussion with Jeremy. Now we have only raised argument error if no block is passed to
fetch
method with optionforce: true
is set.r? @jeremy