fix(cache): Add new @version data to cache key - #3506
Open
joshlarson wants to merge 1 commit into
Open
joshlarson wants to merge 1 commit into
joshlarson wants to merge 1 commit into
Conversation
joshlarson
enabled auto-merge (squash)
September 17, 2026 19:14
joshlarson
disabled auto-merge
September 17, 2026 19:15
thecristen
reviewed
Sep 18, 2026
| Generate a readable cache key based on the module, function, and arguments. | ||
| """ | ||
|
|
||
| @version Application.compile_env(:dotcom, :version) |
Collaborator
There was a problem hiding this comment.
question: I believe a default is provided elsewhere, but.. should we supply a default value here in case this ends up nil for whatever reason?
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.
Scope
We've run into a number of issues where bugs happen because we introduce a new field, or make some other kind of change, to a struct representing our parsed understanding of some API response, add code that assumes that the new field is there, and then either crash the page or display the wrong thing when the old struct (without the field) is returned from the cache.
The most recent instance of this was #3501, which added a
vehicle_typefield to our%Stops.Stop{}struct, and started using that to determine whether to show the stop ID at the top of the screen. That led to the following scenario (fortunately only indev- we haven't release that feature to prod yet, and hopefully won't until this PR is also merged):%Stops.Stop{}struct that doesn't have avehicle_typefield.%Stops.Stop{}for stop ID853(or whatever). See that itsvehicle_typeisnil(by virtue of not existing), and determine that we should not show the stop ID.Asana Ticket: 🛠️ Automatically invalidate the cache on each deploy
Implementation
Now that we have the currently-deployed version available to us, we can add that ID (which will change any time the code changes) to the cache key.
Screenshots
How to test
This is a bit arduous to check, especially because
@versionis set at compile-time, so changing it when running locally can be a bit annoying (you'll get errors if you changeSENTRY_RELEASEin your.envwithout also runningmix clean).But you can do the following...
To see the bug:
iex -S mix phx.server.Dotcom.Cache.Multilevel.flushin that iEX shell.iex -S mix phx.server. (Do not clear the cache)To see the fix:
jdl/fix/put-version-in-cache-key).iex -S mix phx.server. (Do not clear the cache)To see how this fix will resolve this type of issue moving forward:
git show origin/main...jdl/fix/put-version-in-cache-key | git apply.SENTRY_RELEASEis set to something likelocalorlocal-0in your.envfile.iex -S mix phx.server.Dotcom.Cache.Multilevel.flushin that iEX shell.jdl/fix/put-version-in-cache-key).iex -S mix phx.server. (Do not clear the cache)SENTRY_RELEASEchanging, and you haven't changed it in your.envfileSENTRY_RELEASEwill always change during deploys, unless you redeploy the same version (which wouldn't need a cache-bust anyway).SENTRY_RELEASEto literally any other value (e.g.local-1), runmix clean, and restart.