Add filter to allow conditional max cache ages#171
Merged
matt-bernhardt merged 2 commits intomasterfrom Apr 30, 2025
Merged
Conversation
2d01eab to
e6ee3c0
Compare
** Why are these changes being introduced: There are several paths which have proven problematic under our current caching setup (where content lasts for a week before re-rendering) 1. The hours grid, which accepts a URL parameter to highligh specific days. 2. The news site's events page 3. The exhibit site's homepage 4. The exhibit site's event index, which contains lists of current, future, and past exhibits. Each of these pages doesn't work well when cached for more than a day, because content can get out of date after 24 hours. ** Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/web-2050 * https://mitlibraries.atlassian.net/browse/web-2052 ** How does this address that need: This adds a function to the parent theme which implements the add_filter command provided by WordPress. This allows us to define a conditional that assigns the cache length according to defined logic - logic which can be pretty flexible in the checks it performs. The default response from this function is the existing cache length of one week. ** Document any side effects to this change: * The function is being defined within the parent theme, which gives it reach across the network only because everything on the network uses either the parent theme or one descended from it. Content within a site other than the parent site is a little awkward to identify, so there is a $site variable defined that seems to use PHP's parse_url to extract the site slug reliably. * Because we are implementing this filter to occasionally define the max cache lifetime, the existing admin UI that also allows site admins to set a default cache length will get disabled. This moves the cache length management firmly into the realm of engineers and version control, and away from site admins. * Code Climate is flagging the next bit of functions.php for a poorly formatted function comment - so I'm fixing it here, even though it isn't strictly necessary.
e6ee3c0 to
286ecd2
Compare
** Why are these changes being introduced: We define some custom Composer commands to remind engineers of the syntax to use for multidev management. One of those commands is focused on the search-replace commands to manipulate database contents, but this workflow has recently found a second step to more accurately manage db contents. Specificially, after the blunt tool to update domain names, there needs to be a second, more targeted, command to revert some email addresses that need to preserved with the original value in order for WordPress to still be able to send emails. ** Relevant ticket(s): n/a ** How does this address that need: This updates the existing multidev-search-replace-syntax command to also provide the suggested syntax for this second command. Like before, this command is only echoed to the terminal, and not run directly. ** Document any side effects to this change: * The search-replace command does not currently adapt to multidevs that have a custom domain assigned (live, test, dev, and stage). That is a known issue with this command, which I've chosen not to try and solve here.
JPrevost
approved these changes
Apr 30, 2025
Member
JPrevost
left a comment
There was a problem hiding this comment.
This looks like what we discussed. Thanks for implementing and 🤞🏻 it works as we think it will!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why are these changes being introduced:
There are several paths which have proven problematic under our current caching setup (where content lasts for a week before re-rendering)
Each of these pages doesn't work well when cached for more than a day, because content can get out of date after 24 hours.
Relevant ticket(s):
https://mitlibraries.atlassian.net/browse/web-2050
https://mitlibraries.atlassian.net/browse/web-2052
How does this address that need:
This adds a function to the parent theme which implements the add_filter command provided by WordPress. This allows us to define a conditional that assigns the cache length according to defined logic - logic which can be pretty flexible in the checks it performs. The default response from this function is the existing cache length of one week.
Document any side effects to this change:
The function is being defined within the parent theme, which gives it reach across the network only because everything on the network uses either the parent theme or one descended from it. Content within a site other than the parent site is a little awkward to identify, so there is a $site variable defined that seems to use PHP's parse_url to extract the site slug reliably.
Because we are implementing this filter to occasionally define the max cache lifetime, the existing admin UI that also allows site admins to set a default cache length will get disabled. This moves the cache length management firmly into the realm of engineers and version control, and away from site admins.
Code Climate is flagging the next bit of functions.php for a poorly formatted function comment - so I'm fixing it here, even though it isn't strictly necessary.
To confirm these changes
The Pantheon documentation about its CDN caching includes a helpful command to poke at cache status via a terminal:
Poking at various URLs on the multidev attached to this branch should allow you to observe the
max-ageparameter changing as different branches of this function are activated.Developer
Stylesheets
string incremented.
Secrets
Documentation
Accessibility
our guide and
all issues introduced by these changes have been resolved or opened as new
issues (link to those issues in the Pull Request details above)
Stakeholder approval
Dependencies
NO dependencies are updated
Code Reviewer
(not just this pull request message)