Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Static cache response statuses #10334

Merged
merged 4 commits into from
Jun 19, 2024
Merged

Conversation

jasonvarga
Copy link
Member

@jasonvarga jasonvarga commented Jun 19, 2024

This PR allows developers to figure out if a given response was statically cached or not.

For example, in a custom middleware...

public function handle($request, $next)
{
    $response = $next($request);

    if ($response->wasStaticallyCached()) {
      // the request was previously cached and has just been retrieved.
    } else {
      // the request was not previously cached and has just been rendered from scratch
    }

    return $response;
}

The ResponseStatusTracker class exists purely because we can't put arbitrary properties on classes in PHP anymore. If we could, we'd just pop a $staticCacheResponseCode property on the Request via a macro. Alas.

The ResponseStatus enum will let us have different statuses for static cache types, similar to how Cloudflare does it. e.g. hit for when serving from cache, miss when served fresh, etc. This PR only introduces hit for now.

We considered simply adding X-Statamic-Static-Cache: hit headers to the response and let developers read those - but we don't want to expose that people are using Statamic. Some people don't like that.

@jasonvarga jasonvarga marked this pull request as ready for review June 19, 2024 15:41
@jasonvarga jasonvarga merged commit 52f8508 into 5.x Jun 19, 2024
17 checks passed
@jasonvarga jasonvarga deleted the static-cache-response-statuses branch June 19, 2024 15:58
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.

None yet

1 participant