Skip to content

Fix Link caching stale resource after a mutating request - #322

Merged
dblock merged 1 commit into
codegram:masterfrom
dblock:dblock/fix-stale-resource-cache-after-mutation
Aug 26, 2026
Merged

Fix Link caching stale resource after a mutating request#322
dblock merged 1 commit into
codegram:masterfrom
dblock:dblock/fix-stale-resource-cache-after-mutation

Conversation

@dblock

@dblock dblock commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Fixes #107.

Link#http_method previously cached every HTTP response (GET, POST, PUT, PATCH, DELETE) into @resource, and #_resource returned @resource if set rather than fetching fresh. 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 a fresh GET, requiring users to instantiate a new client between a _post and a _get (as described in #107).

Only cache the response for GET requests now, and clear the delegate_method memoized @delegate on 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.

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>
@github-actions

Copy link
Copy Markdown

Danger Report

No issues found.

View run

@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 100.0%. remained the same — dblock:dblock/fix-stale-resource-cache-after-mutation into codegram:master

@dblock
dblock merged commit 56d5a87 into codegram:master Aug 26, 2026
10 checks passed
@dblock
dblock deleted the dblock/fix-stale-resource-cache-after-mutation branch August 26, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Between a _post and a _get, need a fresh client?

2 participants