Shorten cache lifetime for location pages to 1 hr - #205
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates Pantheon cache max-age overrides in the parent theme so that location pages rotate featured experts more frequently by reducing their cache lifetime from one week to one hour.
Changes:
- Added a cache-lifetime override branch to detect location page templates.
- Set max-age for location template pages to
1 * HOUR_IN_SECONDS(matching other short-lived pages).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } elseif ( is_page_template( 'templates/page-location.php' ) || is_page_template( 'templates/page-location-2021.php' ) ) { | ||
| return 1 * HOUR_IN_SECONDS; |
There was a problem hiding this comment.
I'm not sure I agree with extraction in this case. Line 282 isn't a clean repetition of this condition, because that check includes the study spaces page:
if ( is_page_template( 'templates/page-location-2021.php' ) || is_page_template( 'templates/page-location.php' ) || is_page_template( 'templates/page-study-spaces.php' ) ) {
wp_enqueue_script( 'parent-hours' );
}
Line 560 is a better match, but on the whole that's now a false promise of abstraction because we'd still need to be aware that there's this one helper method that we need to maintain while there are a lot of other bespoke checks around the source code.
** Why are these changes being introduced: In practice, having location pages last for one week in the cache means that users very rarely see more than one featured expert. We would like users to, as they reload a location page (or visit it more than once) to have a greater probability of seeing different experts. ** Relevant ticket(s): * https://mitlibraries.atlassian.net/browse/pw-188 ** How does this address that need: This adds a branch to the caching logic in the parent theme, resulting in location pages (those using the location or location-2021 templates) to only be cached for one hour - instead of one week. This change only applies to anonymous users, and authenticated users should already trigger a from-scratch page rendering each time they hit refresh. ** Document any side effects to this change: Our cache control logic gets yet more complicated, and this is the first time we're checking page templates in the process (previously we have only used is_page() and the $site variable). However, the is_page_template() function is a stable function provided by WordPress so we don't need to rely on any additional trickery. Additionally, shortening the cache lifetime in this way is not a guarantee that users _will_ see more experts - the logic that selects an expert is liable to repeatedly land on the same expert, and this outcome gets more likely when there are fewer available experts to choose from. When it isn't clear how often users are loading a location page multiple times, I can't say that this will be hugely impactful.
djanelle-mit
left a comment
There was a problem hiding this comment.
This works as expected on the multidev, I'm seeing experts rotate after an hour.
The logic check seems really reasonable.
This looks good to me!
** Why are these changes being introduced:
In practice, having location pages last for one week in the cache means that users very rarely see more than one featured expert. We would like users to, as they reload a location page (or visit it more than once) to have a greater probability of seeing different experts.
** Relevant ticket(s):
** How does this address that need:
This adds a branch to the caching logic in the parent theme, resulting in location pages (those using the location or location-2021 templates) to only be cached for one hour - instead of one week.
This change only applies to anonymous users, and authenticated users should already trigger a from-scratch page rendering each time they hit refresh.
** Document any side effects to this change:
Our cache control logic gets yet more complicated, and this is the first time we're checking page templates in the process (previously we have only used is_page() and the $site variable). However, the is_page_template() function is a stable function provided by WordPress so we don't need to rely on any additional trickery.
Additionally, shortening the cache lifetime in this way is not a guarantee that users will see more experts - the logic that selects an expert is liable to repeatedly land on the same expert, and this outcome gets more likely when there are fewer available experts to choose from. When it isn't clear how often users are loading a location page multiple times, I can't say that this will be hugely impactful.
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)