← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

CDN Edge Caching

Performance PHP 5.0+ Intermediate
debt(d7/e3/b5/t7)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). Tools listed (Lighthouse, Cloudflare, Fastly, Varnish) can surface missing Cache-Control headers or caching anomalies, but misconfigured caching — especially authenticated responses being cached or Vary headers being wrong — typically only manifests in production under real traffic conditions. Lighthouse can flag missing cache headers on static assets, but the more dangerous mistakes (caching user-specific responses) are silent until a user reports seeing another user's data.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix indicates setting Surrogate-Control or Cache-Control headers on PHP responses, which is a targeted header addition. However, fixing the full set of common_mistakes (content-hashed filenames, Vary headers, separating authenticated from public responses) touches multiple response paths and may require reviewing several controllers or middleware, making it slightly more than a one-liner but still within a single component scope.

b5 Burden Structural debt — long-term weight of choosing wrong

Closest to 'persistent productivity tax' (b5). CDN caching configuration applies to all public-facing web responses in the PHP application. Every new endpoint or page added must consider whether it is cacheable, what Cache-Control values to set, and how to handle cache invalidation. This is an ongoing productivity tax across many work streams (new features, API endpoints, asset pipelines) without reshaping the entire architecture.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception field states explicitly: developers assume CDN caching is automatic, leading to two opposite failure modes — either nothing is cached (wasted infrastructure) or everything is cached including authenticated responses (security/correctness violation). This directly contradicts reasonable developer intuition about how CDNs behave by default, and the 'cache everything' failure mode has security implications beyond just performance. This is a well-documented gotcha that contradicts how server-side caching (e.g., opcode caches, database caches) works elsewhere.

About DEBT scoring →

Also Known As

CDN caching edge caching Cache-Control CloudFront Fastly

TL;DR

Content Delivery Networks cache responses at edge nodes close to users — reducing latency and origin load, controlled via Cache-Control headers.

Explanation

A CDN sits between users and your origin server. Edge nodes cache responses based on Cache-Control directives: max-age (how long to cache), s-maxage (CDN-specific, overrides max-age), stale-while-revalidate (serve stale while fetching fresh), stale-if-error (serve stale on origin error). Vary header tells the CDN which request headers produce different responses. Cache purging invalidates content before expiry. For PHP: static assets get long max-age with content-hashed filenames; API responses need short max-age or no-store for authenticated content.

Diagram

flowchart TD
    REQ[User Request] --> EDGE{CDN Edge<br/>has cached response?}
    EDGE -->|HIT - serve from edge| FAST[Response in ms<br/>origin not contacted]
    EDGE -->|MISS| ORIGIN[Origin Server]
    ORIGIN -->|response + Cache-Control| EDGE
    EDGE -->|cache and serve| USER[User]
    subgraph Cache-Control Headers
        PUB[public s-maxage=60<br/>CDN caches 60s]
        PRIV[private no-store<br/>CDN never caches]
        IMM[max-age=31536000 immutable<br/>hashed assets - 1 year]
    end
style FAST fill:#238636,color:#fff
style PUB fill:#238636,color:#fff
style PRIV fill:#d29922,color:#fff
style IMM fill:#238636,color:#fff

Common Misconception

CDN caching is automatic — without explicit Cache-Control headers, CDNs either don't cache or cache everything including authenticated responses, both of which are wrong.

Why It Matters

A correctly configured CDN can serve 90%+ of traffic without touching your origin — reducing server load, latency, and infrastructure costs dramatically.

Common Mistakes

  • No Cache-Control header — CDN may cache nothing or cache everything including user-specific responses.
  • Caching authenticated API responses — user A's data served to user B when auth headers vary.
  • Not using content-hashed filenames for assets — short max-age on static assets kills CDN hit rate.
  • Forgetting Vary: Accept-Encoding — CDN serves gzip response to client that cannot decompress it.

Code Examples

✗ Vulnerable
// No cache headers — CDN caches nothing or caches incorrectly:
function sendResponse(array $data): void {
    header('Content-Type: application/json');
    // No Cache-Control — CDN guesses or caches authenticated responses!
    echo json_encode($data);
}
✓ Fixed
// Explicit cache control per content type:
// Public API data — CDN caches for 60s:
header('Cache-Control: public, s-maxage=60, stale-while-revalidate=300');

// Authenticated data — never cache at CDN:
header('Cache-Control: private, no-store');

// Static assets with content hash in filename:
// app.a3f2c1.js — safe to cache for 1 year:
header('Cache-Control: public, max-age=31536000, immutable');

Added 15 Mar 2026
Edited 22 Mar 2026
Views 92
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
3 pings S 0 pings M 0 pings T 0 pings W 1 ping T 0 pings F 2 pings S 0 pings S 1 ping M 1 ping T 0 pings W 0 pings T 0 pings F 1 ping S 1 ping S 1 ping M 1 ping T 0 pings W 0 pings T 0 pings F 1 ping S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 1 ping F 0 pings S 0 pings S 0 pings M
No pings yet today
No pings yesterday
Amazonbot 11 PetalBot 10 ChatGPT 7 Ahrefs 6 Perplexity 5 SEMrush 5 Scrapy 5 Bing 4 Google 3 Applebot 3 Unknown AI 2 Brave Search 2 Meta AI 1 Twitter/X 1 Baidu 1
crawler 62 crawler_json 4
DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Medium
⚡ Quick Fix
Set Surrogate-Control or Cache-Control headers on PHP responses that are safe to cache — pages with no user-specific content can be cached at the CDN edge for seconds or minutes, dramatically reducing origin load
📦 Applies To
PHP 5.0+ web
🔗 Prerequisites
🔍 Detection Hints
PHP rendering same HTML for every anonymous visitor without CDN caching; no Cache-Control headers on public pages; Vary cookie breaks CDN caching
Auto-detectable: ✓ Yes lighthouse cloudflare fastly varnish
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: Medium ✗ Manual fix Fix: Medium Context: File


✓ schema.org compliant