You inherit a content site whose origin is a 4 vCPU VM that crumbles every time a post gets shared on a large subreddit. The site has Cloudflare in front, but it’s free-tier without APO, so the HTML still hits origin on every request. You evaluate BunnyCDN and find Perma-Cache — an edge store that, unlike regular CDN cache, doesn’t evict on TTL or LRU. Once a URL is cached, it stays cached until you explicitly purge it. The challenge is wiring it up so logged-in editors don’t see stale pages and so the WP plugin actually purges the edge when you publish.
What’s happening
BunnyCDN has two cache tiers:
- Regular pull zone cache — TTL-bound, LRU-evicted, lives on each PoP’s local disk. Default for static assets.
- Perma-Cache — written once to a configurable storage zone (Bunny Storage), served from the edge indefinitely. Cache invalidation is purge-only; TTLs do not apply.
For WordPress, the architecture that holds up is:
- A pull zone with origin set to your WordPress origin host (
origin.example.com). - Perma-Cache enabled on the pull zone with a backing storage region close to your audience (e.g., FRA for Europe, NY for North America).
- Custom hostname (
www.example.com) bound to the pull zone with a SSL cert (BunnyCDN provisions free Let’s Encrypt, or you upload your own). - The
bunnycdnWP plugin (or a small custom integration) calling Bunny’s purge API onsave_post,delete_post, comment events, and theme/plugin updates. - nginx at origin restoring the client IP from
CDN-PullRequest/X-Forwarded-Forand serving with cache-friendly headers.
The traps:
CookieandAuthorizationheaders killing the cache. Perma-Cache only stores responses that are deterministic for an anonymous request. AnySet-Cookieon the response, or anyVary: Cookieheader from origin, opts the response out.- Wrong cache key. By default Perma-Cache keys by URL + query string. If WordPress is serving the same content under both
/post-name/and/?p=42, you double-cache. - Purge granularity. Bunny’s purge API supports single-URL purge, wildcard purge (
https://www.example.com/category/*), and full-zone purge. Single-URL is what the WP plugin uses by default; wildcard is what you need when a post update should invalidate/category/news/,/tag/launch/,/page/2/, etc.
How to verify
Confirm you’re hitting Perma-Cache, not the regular pull cache:
curl -sI https://www.example.com/ \
| grep -iE '^(cdn-cache|cdn-pullzone|cdn-cachedat|server)'
Healthy Perma-Cache hit:
server: BunnyCDN-DE1-1066
cdn-pullzone: 12345
cdn-cache: HIT
cdn-cachedat: Mon, 14 May 2026 09:12:33 GMT
A cdn-cache: MISS followed by a HIT 200ms later means the request fell through to origin and Perma-Cache then stored it.
Check what cookies origin is setting on anonymous requests — same audit as the Cloudflare APO case:
curl -sI https://origin.example.com/ | grep -i '^set-cookie'
Anything other than the wordpress_logged_in / wp-settings / wordpress_test_cookie pattern needs to be stripped at origin before the response leaves.
Confirm purges are actually reaching Bunny. Tail origin nginx for User-Agent: BunnyCDN- (PoP-driven re-fetches) and watch for them after you trigger a publish:
tail -f /var/log/nginx/access.log | grep -i bunnycdn
A publish should produce a small burst of revalidation requests within ~10 seconds.
Audit the Bunny pull zone settings via their API:
ACCOUNT_KEY="<your-account-key>"
ZONE_ID=12345
curl -sH "AccessKey: $ACCOUNT_KEY" \
https://api.bunny.net/pullzone/$ZONE_ID | jq '{
Name, OriginUrl, EnableGeoZoneAfrica: .EnableGeoZoneAF,
EnableCacheSlice, PermaCacheStorageZoneId,
CacheControlMaxAgeOverride, EnableHostnameVary,
DisableCookies, CacheErrorResponses
}'
You want:
PermaCacheStorageZoneIdset to a non-zero storage zone ID.DisableCookies: true— Bunny strips cookies before caching.CacheControlMaxAgeOverride: 31536000(1 year, since purge is authoritative).EnableHostnameVary: falseunless you serve multiple hostnames from one zone.
The fix
Step 1 — create the pull zone and Perma-Cache backing storage. Use Bunny’s API for reproducibility:
ACCOUNT_KEY="<your-account-key>"
# Create storage zone for Perma-Cache (replicated across regions)
curl -sH "AccessKey: $ACCOUNT_KEY" -H "Content-Type: application/json" \
-d '{
"Name": "example-permacache",
"Region": "DE",
"ReplicationRegions": ["NY","LA"],
"ZoneTier": 1
}' \
https://api.bunny.net/storagezone | jq
# Create pull zone pointing at origin, link it to the storage zone above
STORAGE_ZONE_ID=$(curl -sH "AccessKey: $ACCOUNT_KEY" \
https://api.bunny.net/storagezone | jq '.[] | select(.Name=="example-permacache") | .Id')
curl -sH "AccessKey: $ACCOUNT_KEY" -H "Content-Type: application/json" \
-d "{
\"Name\": \"example-com\",
\"OriginUrl\": \"https://origin.example.com\",
\"PermaCacheStorageZoneId\": $STORAGE_ZONE_ID,
\"DisableCookies\": true,
\"CacheControlMaxAgeOverride\": 31536000,
\"EnableQueryStringOrdering\": true
}" \
https://api.bunny.net/pullzone | jq
Step 2 — bind your hostname and provision TLS:
ZONE_ID=<id-from-previous-step>
curl -sH "AccessKey: $ACCOUNT_KEY" -H "Content-Type: application/json" \
-d '{"Hostname": "www.example.com"}' \
https://api.bunny.net/pullzone/$ZONE_ID/addHostname
# Request a free Let's Encrypt cert
curl -sH "AccessKey: $ACCOUNT_KEY" \
"https://api.bunny.net/pullzone/loadFreeCertificate?hostname=www.example.com"
Then point DNS:
www.example.com. 300 CNAME example-com.b-cdn.net.
Step 3 — configure origin nginx. Strip cookies for anonymous traffic and restore the real client IP:
# /etc/nginx/conf.d/wordpress-bunny.conf
map $http_cookie $sh_logged_in {
default 0;
"~*wordpress_logged_in_" 1;
}
# BunnyCDN edge ranges — refresh from https://api.bunny.net/system/edgeserverlist
set_real_ip_from 23.83.128.0/19;
set_real_ip_from 169.150.213.0/24;
set_real_ip_from 138.199.0.0/16;
real_ip_header CDN-PullRequest;
real_ip_recursive on;
server {
listen 443 ssl http2;
server_name origin.example.com;
root /var/www/wordpress;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
if ($sh_logged_in = 0) {
more_clear_headers "Set-Cookie";
}
# Hint to Bunny that anonymous responses are cacheable for 1 year
if ($sh_logged_in = 0) {
add_header Cache-Control "public, max-age=31536000, immutable" always;
}
if ($sh_logged_in = 1) {
add_header Cache-Control "private, no-store" always;
}
include fastcgi_params;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
Step 4 — wire WordPress purges to Bunny. The official bunnycdn plugin handles save_post and a few other hooks. Extend it for category/tag/home invalidation:
<?php
// wp-content/mu-plugins/sh-bunny-purge.php
define('SH_BUNNY_API_KEY', 'your-account-key-here');
define('SH_BUNNY_ZONE_ID', 12345);
function sh_bunny_purge(array $urls): void {
foreach (array_unique($urls) as $url) {
wp_remote_post('https://api.bunny.net/purge?url=' . urlencode($url), [
'headers' => ['AccessKey' => SH_BUNNY_API_KEY],
'timeout' => 5,
]);
}
}
add_action('save_post', function($post_id, $post) {
if (wp_is_post_revision($post_id) || $post->post_status !== 'publish') return;
$urls = [
get_permalink($post_id),
home_url('/'),
home_url('/feed/'),
home_url('/sitemap.xml'),
];
foreach (get_the_category($post_id) as $cat) {
$urls[] = get_category_link($cat->term_id);
// Wildcard purge for paginated archives
$urls[] = rtrim(get_category_link($cat->term_id), '/') . '/*';
}
foreach (get_the_tags($post_id) ?: [] as $tag) {
$urls[] = get_tag_link($tag->term_id);
}
sh_bunny_purge($urls);
}, 10, 2);
// Comment events
add_action('wp_insert_comment', function($id, $comment) {
if ($comment->comment_approved == '1') {
sh_bunny_purge([get_permalink($comment->comment_post_ID)]);
}
}, 10, 2);
// Theme / plugin updates → flush everything
add_action('upgrader_process_complete', function($upgrader, $hook_extra) {
if (in_array($hook_extra['type'] ?? '', ['plugin','theme','core'])) {
wp_remote_post(
'https://api.bunny.net/pullzone/' . SH_BUNNY_ZONE_ID . '/purgeCache',
['headers' => ['AccessKey' => SH_BUNNY_API_KEY], 'timeout' => 10]
);
}
}, 10, 2);
Step 5 — add WP-CLI commands for operators. A purge-by-pattern command is invaluable when content team changes a category slug:
# wp-cli command (paste into a small plugin or use eval)
wp eval '
$pattern = "https://www.example.com/category/news/*";
wp_remote_post("https://api.bunny.net/purge?url=" . urlencode($pattern) . "&async=false", [
"headers" => ["AccessKey" => "your-account-key-here"],
"timeout" => 15,
]);
'
Step 6 — verify Perma-Cache hit ratio. Bunny’s dashboard shows cache hit ratio per pull zone. For a content site running this configuration, anonymous HTML hit ratio should sit at 97-99%. If it’s below 95%, run the cookie audit from “How to verify” — origin is leaking Set-Cookie somewhere.
Stack Harbor operates BunnyCDN Perma-Cache in front of enterprise WordPress operations environments, including the nginx tuning and mu-plugin shims above. If you’re paying for a CDN but origin is still doing the work, book a CDN audit.