Skip to content

Shorten cache lifetime for location pages to 1 hr - #205

Merged
matt-bernhardt merged 1 commit into
masterfrom
pw-188
Aug 10, 2026
Merged

Shorten cache lifetime for location pages to 1 hr#205
matt-bernhardt merged 1 commit into
masterfrom
pw-188

Conversation

@matt-bernhardt

@matt-bernhardt matt-bernhardt commented Aug 7, 2026

Copy link
Copy Markdown
Member

** 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

  • Any theme or plugin whose stylesheets have changed has had its version
    string incremented.
  • No stylesheets are changed

Secrets

  • All new secrets have been added to Pantheon tiers
  • Relevant secrets have been updated in Github Actions
  • All new secrets documented in README
  • No secrets are impacted

Documentation

  • Project documentation has been updated
  • No documentation changes are needed

Accessibility

  • ANDI or Wave has been run in accordance to
    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)
  • No a11y changes are implicated

Stakeholder approval

  • Stakeholder approval has been confirmed
  • Stakeholder approval is not needed

Dependencies

NO dependencies are updated

Code Reviewer

  • The commit message is clear and follows our guidelines
    (not just this pull request message)
  • The changes have been verified
  • The documentation has been updated or is unnecessary
  • New dependencies are appropriate or there were no changes

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +142 to +143
} elseif ( is_page_template( 'templates/page-location.php' ) || is_page_template( 'templates/page-location-2021.php' ) ) {
return 1 * HOUR_IN_SECONDS;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 djanelle-mit left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@matt-bernhardt
matt-bernhardt merged commit b4418f7 into master Aug 10, 2026
4 checks passed
@matt-bernhardt
matt-bernhardt deleted the pw-188 branch August 10, 2026 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants