Skip to content

[6.x] Fix lost URL tracking in the static cache under concurrent requests - #15606

Merged
jasonvarga merged 2 commits into
statamic:6.xfrom
edalzell:fix/static-cache-url-list-lock
Oct 7, 2026
Merged

jasonvarga merged 2 commits into
statamic:6.xfrom
edalzell:fix/static-cache-url-list-lock

Conversation

@edalzell

@edalzell edalzell commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

The half-measure static cache tracks cached responses in one list per domain (static-cache:<md5(domain)>.urls). cacheUrl() updates it with an unlocked read-modify-write, so two requests caching different pages at once both read the same list and the last writer wins. The dropped page's static-cache:responses:<md5> key still exists and is still served, but flush(), invalidateUrl() and static:clear only walk the list, so it serves stale content until a full application cache clear. forgetUrl() has the same problem. The middleware lock is per URL hash, so it doesn't help across different pages.

Fix: wrap the read-modify-write in cacheUrl() and forgetUrl() in a static-cache:urls cache lock, same guarded pattern as Outpost. Non-LockProvider stores run unlocked as before; a lock timeout falls back to the unlocked write. Covers both ApplicationCacher and FileCacher.

Tests: one asserts the list is only written inside the lock; a pcntl_fork test with a real file store reproduces the race (lost 3–5 of 200 entries before, 200/200 after). Skipped where pcntl is unavailable.

@edalzell
edalzell force-pushed the fix/static-cache-url-list-lock branch from 4e3f193 to 6a6224d Compare October 7, 2026 20:13
@jasonvarga
jasonvarga merged commit 7b35de1 into statamic:6.x Oct 7, 2026
62 checks passed
@edalzell
edalzell deleted the fix/static-cache-url-list-lock branch October 23, 2026 17:00
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.

2 participants