Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Reading https://guides.rubyonrails.org/caching_with_rails.html#low-level-caching it makes me wonder if the following code wouldn't be the same:
You don't have the debug info about cache hits and misses, but I wonder how many people care about that. I'd just trust the fetch API to do the right thing.
https://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html#method-i-fetch is the exact API for that.
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.
And just after I post it I think I realize the reason: expiry does a DB call.
Now that I think about it more: this has been on the agenda to replace with Action Cable: https://edgeguides.rubyonrails.org/action_cable_overview.html can use websockets to keep the connection open. It would mean you no longer need to poll, which reduces the need to cache. We still do a lot of full page loads so it's not completely gone, but helps a lot. Probably an interesting area for optimization.
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.
Good find, I'm not sure all that debug info is necessarily worth it either vs. leaning into using the conventions outlined by Rails guide itself.