function my_pantheon_varnish_caching() {
if ( is_user_logged_in() ) {
return;
}
$age = false;
// Home page: 30 minutes
if ( is_home() && get_query_var( 'paged' ) < 2 ) {
$age = 30;
// Product pages: two hours
} elseif ( function_exists( 'is_product' ) && is_product() ) {
$age = 120;
}
if ( $age !== false ) {
pantheon_varnish_max_age( $age );
}
}
function pantheon_varnish_max_age( $minutes ) {
$seconds = absint( $minutes ) * 60;
header( 'Cache-Control: public, max-age=' . $seconds );
}
add_action( 'template_redirect', 'my_pantheon_varnish_caching' );