Cache rules define how Sudun caches and serves content from edge servers. Properly configured cache rules improve performance, reduce origin load, and enhance user experience.
Request → Edge Server → Cache Check
│
┌───────┴───────┐
│ │
Cache HIT Cache MISS
│ │
Return cached Fetch from origin
content Cache response
Return to user
By default, Sudun caches content based on:
| Content Type | Default TTL | Cacheable |
|---|---|---|
| Images (jpg, png, gif, webp) | 1 day | Yes |
| CSS, JavaScript | 1 day | Yes |
| Fonts (woff, woff2, ttf) | 1 day | Yes |
| HTML | Not cached | No |
| API responses | Not cached | No |
| Component | Description | Example |
|---|---|---|
| Match Criteria | Conditions to match requests | URL path, file extension |
| Cache Action | How to handle matched requests | Cache, Bypass, Override |
| TTL | Time to live in cache | 3600 (1 hour) |
# Exact match
/images/logo.png
# Prefix match
/static/*
# Wildcard match
/api/*/public
# Regex match (advanced)
^/blog/[0-9]{4}/.*$
Cache by file type:
{
"match": {
"file_extension": ["jpg", "jpeg", "png", "gif", "webp", "css", "js"]
},
"action": "cache",
"ttl": 86400
}
{
"match": {
"path": "/search",
"query_string": {
"contains": "category"
}
}
}
{
"match": {
"headers": {
"Accept": "application/json"
}
},
"action": "bypass"
}
Store content at edge servers:
{
"match": { "path": "/static/*" },
"action": "cache",
"ttl": 604800,
"settings": {
"browser_ttl": 86400,
"serve_stale": true
}
}
Always fetch from origin:
{
"match": { "path": "/api/*" },
"action": "bypass"
}
Ignore origin cache headers:
{
"match": { "path": "/assets/*" },
"action": "override",
"ttl": 2592000,
"ignore_origin_headers": true
}
How long content stays cached at edge servers:
| Value | Duration | Use Case |
|---|---|---|
| 60 | 1 minute | Frequently updated content |
| 3600 | 1 hour | Semi-dynamic content |
| 86400 | 1 day | Static assets |
| 604800 | 1 week | Rarely changing content |
| 2592000 | 30 days | Versioned assets |
How long browsers cache content locally:
{
"edge_ttl": 86400,
"browser_ttl": 3600
}
Tip: Set browser TTL shorter than edge TTL to maintain control over cache invalidation.
The cache key determines what makes a cached object unique.
https://example.com/page?sort=date&page=1
│ │ │
Scheme Path Query String
| Option | Behavior |
|---|---|
| Include All | Cache varies by all query params |
| Exclude All | Ignore query string for caching |
| Include Specific | Only specified params affect cache |
| Exclude Specific | Ignore specified params |
Example: Include specific parameters
{
"cache_key": {
"query_string": {
"include": ["category", "page"]
}
}
}
Vary cache by request headers:
{
"cache_key": {
"headers": ["Accept-Language", "Accept-Encoding"]
}
}
Vary cache by cookies (use sparingly):
{
"cache_key": {
"cookies": ["session_type", "user_tier"]
}
}
Serve cached content while fetching fresh content:
{
"serve_stale": {
"while_revalidate": true,
"on_error": true,
"max_stale_age": 86400
}
}
Serve stale content when origin fails:
Origin Error (5xx) → Serve stale content → Log error
By default, Sudun respects these origin headers:
| Header | Behavior |
|---|---|
| Cache-Control: max-age=X | Cache for X seconds |
| Cache-Control: no-cache | Revalidate before serving |
| Cache-Control: no-store | Do not cache |
| Cache-Control: private | Do not cache at edge |
| Expires | Cache until specified date |
| ETag | Enable conditional requests |
Force caching regardless of origin headers:
{
"match": { "path": "/static/*" },
"action": "cache",
"ttl": 86400,
"respect_origin_headers": false
}
Rules are evaluated in order. First matching rule wins:
Rule 1: /api/* → Bypass (Priority: 1)
Rule 2: /api/public/* → Cache (Priority: 2)
Rule 3: /* → Cache (Priority: 3)
Request: /api/users → Matches Rule 1 → Bypass
Request: /api/public/data → Matches Rule 1 → Bypass (not Rule 2!)
Important: Place more specific rules before general rules.
{
"name": "Static Assets",
"match": {
"file_extension": ["css", "js", "jpg", "png", "gif", "ico", "woff2"]
},
"action": "cache",
"ttl": 2592000,
"browser_ttl": 86400
}
{
"name": "API Bypass",
"match": { "path": "/api/*" },
"action": "bypass"
}
{
"name": "HTML Pages",
"match": {
"file_extension": ["html"],
"path": "/*"
},
"action": "cache",
"ttl": 300,
"serve_stale": true
}
{
"name": "Versioned Assets",
"match": {
"path": "/assets/v*/*"
},
"action": "cache",
"ttl": 31536000,
"immutable": true
}
Check the X-Cache-Status response header:
| Status | Meaning |
|---|---|
| HIT | Served from cache |
| MISS | Fetched from origin |
| BYPASS | Cache was bypassed |
| EXPIRED | Cache expired, revalidating |
| STALE | Served stale content |
# Check cache status
curl -I https://example.com/static/style.css
# Response headers
X-Cache-Status: HIT
Cache-Control: max-age=86400
Age: 3600
Manage cache rules via API:
# List cache rules
curl -X GET https://api.Sudun.com/v1/domains/example.com/cache-rules \
-H "Authorization: Bearer YOUR_API_KEY"
# Create cache rule
curl -X POST https://api.yeSudunom/v1/domains/example.com/cache-rules \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "Static Assets",
"match": {"file_extension": ["css", "js", "png"]},
"action": "cache",
"ttl": 86400
}'
Need help with cache rules? Contact support@Sudun.com