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
When using Rails.cache.fetch, Please show warning at mistyping the expires_in option. #39850
Comments
|
I have also run into this problem. Mistyping |
This issue has been automatically marked as stale because it has not been commented on for at least three months. |
That is a good plan. Do any of you are interested in opening a PR to fix this issue adding an alias to |
I am. I’ll get a PR up tomorrow |
The `expires_in` option is easy to misremember or mistype as `expire_in` or `expired_in`, with potentially harmful results. If a developer wants to cache a value for only 2 seconds but mistakenly types `expire_in: 2.seconds`, that value will instead be cached for the default time, likely 6 hours, meaning that users of the site will see the same data for much longer than they should, and the only recovery (short of waiting for the 6 hours to elapse) is to manually expire all relevant keys. This commit allows cache stores to recognize these common typos as aliases by normalizing them before consuming the options. In general, we should be careful about adding too many aliases for options to the cache stores, since each option key used by the base Cache::Store class is one fewer key that each cache implementation can customize for itself. This case was approved because of the similarity of the aliases to the root key and the potential damage caused by mistaking them. Fixes rails#39850.
Problem
When using Rails.cache.fetch, it is easy to mistype the expires_in option.
Incorrectly specified in expires or expired_in,
I haven't noticed it for a long time.
This article specifies expired_in incorrectly.
This article is at the top of the search results, so I think many people have made the same mistakes.
https://morizyun.github.io/ruby/rails-function-cache-fetch-write-delete.html
Improvement plan
If we specify incorrectly such as expires or expired_in,
Please show warning.
https://github.com/rails/rails/blob/master/activesupport/lib/active_support/cache.rb
The text was updated successfully, but these errors were encountered: