We've found that the bubbled max age in some circumstances is lower or higher than we'd like, especially when a site has a cache layer (e.g Cloudfront) in combination with no purging solution.
In the case of max ages being high, such as infinite or multi-day, as a workaround for lack of a purging solution, we'd like to cap the bubbled max age to a configurable ceiling.
In the case of low max age, but not uncacheable, we'd like to enforce a minimum cache age to reduce the load on the server.
Ideally if a proper purging solution is added to a site, the max-age maximum cap would be lifted.
The patch provides the necessary plumbing, configuration is currently set using config overrides in line with a previous issue (#2878459: Remove configurability: simpler to set up (because works immediately), easier to maintain) to make the module UI-less.
Sample configuration for a settings.php
// Values are seconds, valid values are integers greater than zero.
$config['cache_control_override.settings']['max_age']['minimum'] = 1000;
$config['cache_control_override.settings']['max_age']['maximum'] = 9000;
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | 3003716-9.patch | 12.11 KB | jibran |
Issue fork cache_control_override-3003716
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
dpiPatch includes tests.
Test module has been updated to allow for responses without max age.
I've intentionally not shipped any default configuration, as default values should be null.
Comment #3
dpiAutomated tests are currently disabled #3003718: Enable automated testing for Cache Control Override
Comment #4
jibranNeat idea patch looks good to me.
Let's add some comments here.
Why not getMinimumMaxAge() and getMaximumMaxAge()?
Comment #5
dpiAdded extra docs.
I prefer the symmetry/alphabetical ordering. Isn't a concern either way.
Comment #6
jibranWe need to add
config/install/cache_control_override.settings.ymland ahook_update_Nto add it to active storage.Comment #7
jibranHere you go.
Comment #8
jibranAdded schema test.
Comment #9
jibranFixed the failing test.
Comment #10
marcoscanoNice work! This is 👍 from me. I have found just some nitpicks, feel free to disregard if you like.
I'm confused why these default values are necessary, especially due to these descriptions:
Minimum max age, if max age is greater than 0. Leave empty to disable.Maximum max age, if max age is greater than 0. Leave empty to disable.Wouldn't a "no limit by default" be reasonable so that we don't need the install hook and initial values?
(also, in case we do want to leave them, maybe using
Cache::PERMANENTinstead of -1 would make it more self-explanatory?(It's a bit unfortunate #2951046: Allow parsing and writing PHP class constants and enums in YAML files is not in yet so we could use it in the yml file, but at least in the update hook it could make sense? :) )
I guess we could enforce
$maximumhere to also be> 0, even though I admit this is borderline paranoia, since the value can only be defined in settings.php... :)Comment #12
dpiI think its just that when introducing new configs, you should set an initial value. The minimum 0 and maximum -1 values effectively disable this feature for new and existing sites.
Yep, done.
Yeh probably not necessary, especially low values are unlikely. "Max age maximum" is self explanatory.
Comment #13
dpiPushed the patch as a MR above^
Comment #14
kim.pepperComment #18
dpiComment #19
dpiGitlab/d.o are quite broken at the moment so the 2.x/Drupal 10 version of this MR will need to chill for a bit.
Comment #24
dpiHuzzah! GitLab caught up