Skip to content

Commit

Permalink
add a helper function for retrieving the default max age
Browse files Browse the repository at this point in the history
this is helpful so we can always return the filtered value
  • Loading branch information
jazzsequence committed May 13, 2024
1 parent 70fbca8 commit adc0169
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions inc/admin-interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function get_current_max_age() {

// If the default_ttl option is not set, we're using the default, which is 1 week.
if ( ! isset( $options['default_ttl'] ) ) {
return apply_filters( 'pantheon_cache_default_max_age', WEEK_IN_SECONDS );
return get_default_max_age();
}

return apply_filters( 'pantheon_cache_default_max_age', $options['default_ttl'] );
Expand Down Expand Up @@ -163,19 +163,28 @@ function default_cache_max_age_test( $tests ) {
*/
function humanized_max_age( $recommended = false ) {
$time = time();
$current_max_age = $recommended ? apply_filters( 'pantheon_cache_default_max_age', WEEK_IN_SECONDS ) : get_current_max_age();
$current_max_age = $recommended ? get_default_max_age() : get_current_max_age();
$humanized_time = human_time_diff( $time, $time + $current_max_age );

return $humanized_time;
}

/**
* Get the default max-age.
*
* @return int
*/
function get_default_max_age() {
return apply_filters( 'pantheon_cache_default_max_age', WEEK_IN_SECONDS );
}

/**
* The GCDN cache max-age Site Health test.
*
* @return array
*/
function test_cache_max_age() {
$default_max_age = apply_filters( 'pantheon_cache_default_max_age', WEEK_IN_SECONDS );
$default_max_age = get_default_max_age();
$current_max_age = get_current_max_age();
$humanized_time = humanized_max_age();
$humanized_reccomended_time = humanized_max_age( true );
Expand Down

0 comments on commit adc0169

Please sign in to comment.