Caching

Understand how NordicCDN caches your content.


How Caching Works

When a request arrives at an edge server:

  1. Cache Lookup - Check if the content exists in cache
  2. Cache Hit - Return cached content immediately (fast!)
  3. Cache Miss - Fetch from origin, cache the response, return to client

Cache Headers

Origin Cache Headers

We respect standard cache headers from your origin:

Header Purpose
Cache-Control Primary caching directive
Expires Legacy expiration date
ETag Content validation
Last-Modified Content validation

Example origin headers:

Cache-Control: public, max-age=86400
ETag: "abc123"

CDN Cache Headers

Our responses include:

Header Description
X-Cache HIT, MISS, or BYPASS
X-Edge Edge server identifier (e.g., cph-1)
Age Seconds since cached

Cache Control Directives

Cacheable Directives

  • public - Content can be cached by CDN
  • max-age=N - Cache for N seconds
  • s-maxage=N - CDN-specific max age (overrides max-age)

Non-Cacheable Directives

  • private - Don't cache on CDN (user-specific content)
  • no-cache - Validate with origin before serving
  • no-store - Never cache this response

Default Cache Behavior

When your origin doesn't send cache headers:

Content Type Default TTL
Images 1 hour
CSS/JS 1 hour
HTML Not cached
API responses Not cached

You can override these defaults in your zone settings.


Cache Key

The cache key determines how content is stored and retrieved. By default:

Cache Key = Hostname + Path + Query String (if enabled)

Query String Handling

With query string caching enabled:

/style.css?v=1  → Cached separately
/style.css?v=2  → Cached separately

With query string caching disabled:

/style.css?v=1  → Same cache entry
/style.css?v=2  → Same cache entry

Cache Bypass

Content is NOT cached when:

  • Cache-Control: private is present
  • Cache-Control: no-cache is present
  • Cache-Control: no-store is present
  • Response has Set-Cookie header
  • Request has Authorization header
  • Response status is 4xx or 5xx

Best Practices

Use Cache-Control Headers

Set appropriate cache headers on your origin:

# Nginx example
location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
    add_header Cache-Control "public, max-age=2592000";
}

Version Your Assets

Use query strings or filename versioning:

<!-- Query string versioning -->
<link rel="stylesheet" href="/style.css?v=1.2.3">

<!-- Filename versioning -->
<link rel="stylesheet" href="/style.1.2.3.css">

Long TTLs for Static Assets

Static assets that rarely change should have long cache times:

  • Fonts: 1 year
  • Images: 30 days
  • CSS/JS: 7-30 days (with versioning)