Fixed whole-cache clear on routine User/Admin saves - fixes #1270 - #1271
Merged
Merged
Conversation
This was referenced Jul 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
On production, browsers were refetching
/pages/<token>/templatemore often than expected within the same session, even though no app configuration had changed.Root cause (confirmed via production logs):
UserandAdminboth includeAdminHandler, whoseafter_save :invalidate_cachecalledRails.cache.clearunconditionally. SinceUser/Adminrecords are saved on nearly every request (Devisetrackablesign-in tracking,lockablefailed-attempt counters, app-type switching), this wiped the entire shared memcached on routine activity, destroyingApplication.server_cache_versionand forcing a newtemplate_versiontoken for all users.partial_cache_keyinApplicationHelperalso embeddedu&.updated_at, so any user-record save changed the cache key even when nothing relevant (roles/app type/access) had actually changed — e.g. switching app type A→B→A produced a different key than the original A session.Fix
AdminHandler#invalidate_cachenow always resets thelatest_updatememo, but only callsRails.cache.clearwhen the newclear_rails_cache_on_save?predicate (defaulttrue) returns true.UserandAdmineach overrideclear_rails_cache_on_save?to only clear the cache when thedisabledflag actually changes (saved_change_to_disabled?). All otherAdminHandlermodels keep clearing on every save.u&.updated_atsegment frompartial_cache_key, since role/app-type/access changes are already covered by other segments in the key.Testing
spec/models/concerns/admin_handler_cache_invalidation_spec.rb- covers User/Admin cache-clear scoping and confirms otherAdminHandlermodels are unaffected.spec/helpers/application_helper_spec.rbwith#partial_cache_keycoverage - key stability across irrelevant user saves, and correct invalidation on app-type change.admin/app_types_controller_spec.rb,pages_controller_spec.rb,reports_table_helper_spec.rb,admin_helper_spec.rb,handlebars_precompiler_helper_spec.rb.spec/system/user/user_spec.rb.spec/system/memcached_clear_template_recovery_spec.rb.fixes #1270