Fix Link caching stale resource after a mutating request - #322
Merged
dblock merged 1 commit intoAug 26, 2026
Merged
Conversation
Link#http_method previously cached every HTTP response (GET, POST, PUT, PATCH, DELETE) into @resource, and #_resource returned @resource if set. This meant that after a _post/_put/_patch/_delete, subsequent calls that rely on #_resource (method_missing delegation, #each, etc.) would see the mutation's response instead of fetching a fresh resource via GET, requiring users to instantiate a new client to see up-to-date data. Only cache the response for GET requests now, and clear the delegate_method cache after every request so it is recomputed against the current resource. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Danger ReportNo issues found. |
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.
Fixes #107.
Link#http_methodpreviously cached every HTTP response (GET, POST, PUT, PATCH, DELETE) into@resource, and#_resourcereturned@resourceif set rather than fetching fresh. This meant that after a_post/_put/_patch/_delete, subsequent calls that rely on#_resource(method_missingdelegation,#each, etc.) would see the mutation's response instead of a freshGET, requiring users to instantiate a new client between a_postand a_get(as described in #107).Only cache the response for
GETrequests now, and clear thedelegate_methodmemoized@delegateon every request so it is recomputed against the current resource.Added a regression test and confirmed the original repro from #107 now works without needing a fresh client.