liveblog icon indicating copy to clipboard operation
liveblog copied to clipboard

Purge VIP varnish cache if available

Open WPprodigy opened this issue 3 years ago • 1 comments
trafficstars

Opening this to track this closed PR: https://github.com/Automattic/vip-go-mu-plugins/pull/984

If still desired/needed, the cache-purging functionality can be added to this plugin. Perhaps here: https://github.com/Automattic/liveblog/blob/25bc1f0f2e6b53c6ecd1ccec080600e01f54abd8/wpcom-helper.php

WPprodigy avatar Dec 09 '21 20:12 WPprodigy

/**
 * Purge the Varnish cache for a liveblog on each new entry.
 *
 * Ensures that a Liveblog page isn't cached with stale meta data during an
 * active liveblog.
 *
 * @param  int $comment_id ID of the comment for this new entry.
 * @param  int $post_id    ID for this liveblog post.
 */
function wpcom_vip_liveblog_purge_on_new_entries( int $comment_id, int $post_id ){

	if ( ! function_exists( 'wpcom_vip_purge_edge_cache_for_url' ) ) {
		return;
	}

	// Get the URL for this Liveblog post.
	$permalink = get_permalink( absint( $post_id ) );
	if ( ! $permalink ) {
		return;
	}

	// Purge the Varnish cache for the liveblog post so that new loads of the
	// post include the newest entries.
	wpcom_vip_purge_edge_cache_for_url( $permalink );

}
add_action( 'liveblog_insert_entry', 'wpcom_vip_liveblog_purge_on_new_entries', 10, 2 );

WPprodigy avatar Dec 09 '21 20:12 WPprodigy