-
Notifications
You must be signed in to change notification settings - Fork 10
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
Prevent theses and items sitemap views from using the same cache key #3361 #3400
Conversation
f5f1755
to
77808bc
Compare
…3361 * adds a distinct cache key to the partial used by both the theses and items sitemap view
77808bc
to
372cd65
Compare
cache 'sitemap', expires_in: 24.hours do | ||
cache cache_key, expires_in: 24.hours do |
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.
Ensure a unique cache key is generated depending on whether to theses sitemap view or the item sitemap view is rendering the partial.
I'm unsure how to write a test to capture the issue... is one needed? Options I've tried:
- Enable caching in the config/environments/test.rb however there is a possibility for unintended consequences Rails cache prefix is not properly configured for isolated caching during parallel tests. rails/rails#48341
config.action_controller.perform_caching = true
config.cache_store = :memory_store
- A sitemap_test.rb runtime, dynamically enable the cache during setup and disable during the teardown. My limited understanding has found a successful approach. I was unable to get an approach like this https://stackoverflow.com/questions/14249954/how-to-set-perform-caching-dynamically-in-rails to work.
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.
Nice investigate work 👍. The solution makes sense to me.
Regarding testing this, I am kind of in the camp that maybe it's not required? Even if you found a way to test this, the solution would probably introduce a ton of complexity that might not be worth it?
Addresses #3361
Context
The theses and item sitemap views use the same cached partial with the same cache key thus, depending on timing and if caching is enabled (disabled in dev) the theses sitemap sometimes contains item or the items sitemap contains theses. The experience is intermittent if there are multiple load-balanced app servers each with their own in-memory cache store.
What's New
This change adds a unique cache key to the partial to differentiate between the theses and item sitemap view calls to the _object partial.
How to test
#3361 (comment)
bundle exec rails console -e dev --sandbox
app.get "http://era.lvh.me/sitemap-theses.xml"
Rails.cache.instance_variable_get(:@data).keys
app.get "http://era.lvh.me/sitemap-items.xml"
Rails.cache.instance_variable_get(:@data).keys
document = Nokogiri::XML(@response.body)
8.a. Old: theses in the items sitemap even though the request was for items
8.b. PR: items in the items sitemap (no theses)