Problem
On production, browsers refetch /pages/<token>/template more often than expected within the same session, even though app config hasn't changed.
Root cause (confirmed via logs): User and Admin both include AdminHandler, whose after_save :invalidate_cache calls Rails.cache.clear. Since User/Admin are saved on every sign-in (Devise trackable), failed login (lockable), and app-type switch, this wipes the entire shared memcached on nearly every request, destroying Application.server_cache_version and forcing a new template_version token for all users.
Additionally, partial_cache_key (in ApplicationHelper) includes u&.updated_at, so any user-record save changes the cache key even when nothing relevant (roles/app type/access) actually changed — e.g. switching app type A→B→A produces a different key than the original A session.
Plan
- In
AdminHandler#invalidate_cache, keep full Rails.cache.clear for all admin models, but for User/Admin only clear when disabled actually changed (saved_change_to_disabled?); always reset latest_update memo regardless.
- Remove the
u&.updated_at segment from partial_cache_key in ApplicationHelper (role/app-type/access changes are already covered by other segments).
- Add specs covering: user/admin save without disabled change does not clear cache; disabled change does; other AdminHandler models still clear on every save;
partial_cache_key stability across non-relevant user saves.
- Review existing specs referencing the old clear-on-every-save behavior (
admin/app_types_controller_spec.rb, pages_controller_spec.rb, reports_table_helper_spec.rb, memcached_clear_template_recovery_spec.rb).
Longer-term replacement of whole-cache clears with a namespaced/versioned cache-key scheme is out of scope for this issue.
Problem
On production, browsers refetch
/pages/<token>/templatemore often than expected within the same session, even though app config hasn't changed.Root cause (confirmed via logs):
UserandAdminboth includeAdminHandler, whoseafter_save :invalidate_cachecallsRails.cache.clear. SinceUser/Adminare saved on every sign-in (Devisetrackable), failed login (lockable), and app-type switch, this wipes the entire shared memcached on nearly every request, destroyingApplication.server_cache_versionand forcing a newtemplate_versiontoken for all users.Additionally,
partial_cache_key(inApplicationHelper) includesu&.updated_at, so any user-record save changes the cache key even when nothing relevant (roles/app type/access) actually changed — e.g. switching app type A→B→A produces a different key than the original A session.Plan
AdminHandler#invalidate_cache, keep fullRails.cache.clearfor all admin models, but forUser/Adminonly clear whendisabledactually changed (saved_change_to_disabled?); always resetlatest_updatememo regardless.u&.updated_atsegment frompartial_cache_keyinApplicationHelper(role/app-type/access changes are already covered by other segments).partial_cache_keystability across non-relevant user saves.admin/app_types_controller_spec.rb,pages_controller_spec.rb,reports_table_helper_spec.rb,memcached_clear_template_recovery_spec.rb).Longer-term replacement of whole-cache clears with a namespaced/versioned cache-key scheme is out of scope for this issue.