Skip to content

[6.x] Fix stale static cache status on responses in long-lived processes - #15455

Merged
jasonvarga merged 1 commit into
statamic:6.xfrom
petemolinero:fix/weakmap-response-status-tracker
Sep 14, 2026
Merged

jasonvarga merged 1 commit into
statamic:6.xfrom
petemolinero:fix/weakmap-response-status-tracker

Conversation

@petemolinero

Copy link
Copy Markdown
Contributor

Static caching keeps a small lookup table that remembers, for each response, whether it was served from the static cache. That table is keyed by the response's PHP object id, and entries are never removed.

In a normal PHP-FPM request that's harmless: the whole process ends with the request, and the table dies with it. In a long-lived process (e.g. Octane, queue workers) the same PHP process handles many requests, so two things go wrong:

  • Stale answers. PHP recycles object ids once an object is gone. A new response can be handed the id of an old one and inherit its cached status, so wasStaticallyCached() can say "yes" for a response that was never cached.
  • A table that only grows. Every response adds an entry that is never cleaned up.

The fix

Key the table by the response object itself using PHP's WeakMap (added in PHP 8.0), which is a map whose entries are dropped automatically as soon as the object they belong to is gone. No stale ids, no cleanup to remember, and the map never grows past the responses that are still alive. No public API changes: the setStaticCacheResponseStatus, staticCacheResponseStatus, and wasStaticallyCached macros behave exactly as before.

@jasonvarga
jasonvarga merged commit f3a8a78 into statamic:6.x Sep 14, 2026
62 checks passed
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