Add filter to allow conditional max cache ages #171
Merged
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-age
parameter 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)