Alter cache max-age in response

Created on 10 February 2024, 10 months ago
Updated 14 February 2024, 10 months ago

Problem/Motivation

Whilst yes, the response is a 200 - the cache headers still output as:

cache-control: must-revalidate, no-cache, private

And some edge caches need a little prompting to

Steps to reproduce

General use of the module - nothing special.

Proposed resolution

As attached.

Remaining tasks

Test?

User interface changes

Adds a config entry for collecting a cache max-age - I figured this would be better than reusing the system page.max_age as it's for an entirely different purpose.

API changes

N/A.

Data model changes

N/A.

📌 Task
Status

Closed: won't fix

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom pobster

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @pobster
  • Merge request !2Resolve #3420609 "Alter cache max age" → (Closed) created by pobster
  • Status changed to Needs review 10 months ago
  • 🇬🇧United Kingdom pobster

    I'm marking this as for review ... but I haven't even tested it myself yet...

  • Status changed to Postponed 10 months ago
  • 🇬🇧United Kingdom pobster

    Ugh ... okay - that's annoying. Seems this isn't possible without overriding the entire service as it contains;

    \Drupal::service('page_cache_kill_switch')->trigger();

    And it doesn't look like that's able to be reverted :( Lemme think about it, maybe there's another way ...

    edit: I admit I'm maybe a niche case (long-term parking of domains) but this should still be possible IMO.

  • 🇬🇧United Kingdom pobster

    Ugh ... I'm just going to have to do this in Varnish instead. So much for Drupal being flexible.

  • Status changed to Closed: won't fix 10 months ago
  • 🇬🇧United Kingdom pobster

    Here's what I ended up doing:

    sub vcl_recv {
      # Check if this is one of our sites in maintenance mode.
      if (
        req.http.host ~ "^(www\.)?drupal\.org$"
      ) {
        set req.http.X-Maintenance-Mode = "true";
      }
    }
    
    sub vcl_backend_response {
      # Check if we're in maintenance mode.
      if (bereq.http.X-Maintenance-Mode) {
        set beresp.http.Cache-Control = "public, max-age=86400";
        unset beresp.http.Set-Cookie;
        unset beresp.http.X-Maintenance-Mode;
        set beresp.ttl = 1d;
      }
    }
    
Production build 0.71.5 2024