Integration Recipes
WordPress publish hook
Recache a post when it is published or updated, so search bots see the new version on their next visit:
php
<?php
// wp-content/mu-plugins/edgecomet-cache.php
add_action('save_post', function (int $postId, WP_Post $post): void {
if ($post->post_status !== 'publish') {
return;
}
if (wp_is_post_revision($postId) || wp_is_post_autosave($postId)) {
return;
}
$token = getenv('EDGECOMET_TOKEN');
$siteId = getenv('EDGECOMET_SITE_ID');
$url = get_permalink($postId);
if (!$token || !$siteId || !$url) {
return;
}
wp_remote_post(
"https://cloud.edgecomet.com/api/websites/{$siteId}/cache/recache",
[
'timeout' => 5,
'headers' => [
'Authorization' => "Bearer {$token}",
'Content-Type' => 'application/json',
],
'body' => wp_json_encode([
'urls' => [$url],
'priority' => 'high',
]),
]
);
}, 20, 2);Configure EDGECOMET_TOKEN and EDGECOMET_SITE_ID as environment variables - never hard-code the token.
The general pattern
The same shape works for any system with a publish or deploy hook:
- Any CMS - Drupal's
node_update, a custom hook in your admin panel: on publish,POSTthe changed URL to recache withpriority: "high"; on delete,POSTit to invalidate. - Deploy pipelines - after a release that changes many pages, send the affected URLs (or the section's URLs) in batches of up to 1000 at
priority: "normal". - Static site rebuilds - post the list of changed paths from your build's diff step.
Two rules of thumb: send high priority only for the handful of URLs a human just changed, and prefer recache over invalidate whenever the old version can keep serving until the new render is ready.