Cache policies define high-level caching strategies that can be applied across your domain. Policies combine multiple cache settings into reusable configurations, making it easier to manage caching behavior consistently.
A cache policy is a named configuration that specifies:
Cache Policy "Static Assets"
├── TTL: 30 days
├── Browser TTL: 1 day
├── Cache Key: URL + Accept-Encoding
├── Compression: Brotli, Gzip
└── Serve Stale: Enabled
Sudun includes pre-configured policies for common use cases:
Balanced caching for typical websites:
| Setting | Value |
|---|---|
| Edge TTL | Respect origin headers |
| Browser TTL | Respect origin headers |
| Cache Key | URL + Query String |
| Compression | Auto |
| Serve Stale | On error only |
Maximum caching for static content:
| Setting | Value |
|---|---|
| Edge TTL | 30 days |
| Browser TTL | 7 days |
| Cache Key | URL only |
| Compression | Always |
| Serve Stale | Always |
Minimal caching for dynamic content:
| Setting | Value |
|---|---|
| Edge TTL | None |
| Browser TTL | None |
| Cache Key | N/A |
| Compression | On-the-fly |
| Serve Stale | Never |
{
"name": "my-static-policy",
"description": "Policy for static assets",
"settings": {
"cache": {
"edge_ttl": 2592000,
"browser_ttl": 86400,
"respect_origin": false
},
"cache_key": {
"include_query_string": false,
"include_headers": ["Accept-Encoding"]
},
"optimization": {
"compression": "auto",
"minify": false
},
"stale": {
"serve_while_revalidate": true,
"serve_on_error": true,
"max_stale_age": 86400
}
}
}
Control cache duration:
| Setting | Description | Range |
|---|---|---|
| edge_ttl | Time cached at edge | 0 - 31536000 (1 year) |
| browser_ttl | Time cached in browser | 0 - 31536000 |
| respect_origin | Honor origin headers | true/false |
| min_ttl | Minimum cache time | 0 - 86400 |
| max_ttl | Maximum cache time | 0 - 31536000 |
TTL Hierarchy:
If respect_origin = true:
TTL = Origin Cache-Control (within min/max bounds)
If respect_origin = false:
TTL = edge_ttl setting
Define what makes cached content unique:
{
"cache_key": {
"include_query_string": true,
"query_string_whitelist": ["page", "sort"],
"query_string_blacklist": ["utm_*", "fbclid"],
"include_headers": ["Accept-Encoding", "Accept-Language"],
"include_cookies": [],
"include_device_type": false,
"include_geo": false
}
}
Cache Key Options:
| Option | Effect |
|---|---|
| include_query_string | Vary cache by query parameters |
| query_string_whitelist | Only these params affect cache |
| query_string_blacklist | Ignore these params |
| include_headers | Vary cache by request headers |
| include_cookies | Vary cache by cookies |
| include_device_type | Separate mobile/desktop cache |
| include_geo | Separate cache by country |
Configure content compression:
{
"compression": {
"mode": "auto",
"algorithms": ["br", "gzip", "deflate"],
"min_size": 1024,
"types": ["text/*", "application/json", "application/javascript"]
}
}
Compression Modes:
| Mode | Behavior |
|---|---|
| auto | Compress based on content type and size |
| always | Always compress eligible content |
| never | Disable compression |
| origin | Use origin compression only |
Configure stale content behavior:
{
"stale": {
"serve_while_revalidate": true,
"serve_on_error": true,
"max_stale_age": 86400,
"error_codes": [500, 502, 503, 504]
}
}
Assign a policy to specific paths:
{
"policy_assignments": [
{
"policy": "aggressive-static",
"match": {
"path": "/static/*"
}
},
{
"policy": "dynamic",
"match": {
"path": "/api/*"
}
}
]
}
Assign policy by file extension:
{
"policy": "aggressive-static",
"match": {
"file_extensions": ["css", "js", "jpg", "png", "woff2"]
}
}
Assign policy by response content type:
{
"policy": "standard",
"match": {
"content_type": ["text/html", "application/xhtml+xml"]
}
}
Policies can inherit from other policies:
{
"name": "my-images-policy",
"inherits": "aggressive-static",
"overrides": {
"cache": {
"browser_ttl": 604800
},
"optimization": {
"image_optimization": true
}
}
}
Inheritance Chain:
Base Policy: aggressive-static
└── my-images-policy (inherits + overrides browser_ttl)
└── my-hero-images (inherits + overrides image quality)
Track policy changes over time:
{
"name": "static-assets",
"version": 3,
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-15T10:30:00Z",
"changelog": [
{
"version": 3,
"date": "2024-01-15",
"changes": "Increased browser TTL to 7 days"
},
{
"version": 2,
"date": "2024-01-10",
"changes": "Added Brotli compression"
}
]
}
Revert to a previous policy version:
Test policy changes before deployment:
{
"preview": true,
"test_urls": [
"https://example.com/test-page",
"https://example.com/static/test.css"
]
}
Test policy effectiveness:
{
"ab_test": {
"enabled": true,
"variants": [
{
"name": "control",
"policy": "current-policy",
"weight": 50
},
{
"name": "experiment",
"policy": "new-policy",
"weight": 50
}
],
"metrics": ["cache_hit_ratio", "origin_requests", "ttfb"]
}
}
{
"name": "product-pages",
"settings": {
"cache": {
"edge_ttl": 3600,
"browser_ttl": 300
},
"cache_key": {
"include_query_string": true,
"query_string_whitelist": ["variant", "color", "size"]
},
"stale": {
"serve_while_revalidate": true,
"max_stale_age": 3600
}
}
}
{
"name": "blog-content",
"settings": {
"cache": {
"edge_ttl": 600,
"browser_ttl": 60
},
"stale": {
"serve_while_revalidate": true,
"serve_on_error": true
}
}
}
{
"name": "api-cacheable",
"settings": {
"cache": {
"edge_ttl": 60,
"browser_ttl": 0,
"respect_origin": true
},
"cache_key": {
"include_query_string": true,
"include_headers": ["Authorization"]
}
}
}
{
"name": "immutable-assets",
"settings": {
"cache": {
"edge_ttl": 31536000,
"browser_ttl": 31536000,
"immutable": true
},
"cache_key": {
"include_query_string": false
}
}
}
View policy performance metrics:
| Metric | Description |
|---|---|
| Cache Hit Ratio | % of requests served from cache |
| Origin Offload | % reduction in origin requests |
| Bandwidth Saved | Data served from cache |
| Avg TTL | Average time content stays cached |
curl -X POST https://api.Sudun.com/v1/domains/example.com/policies \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "my-policy",
"settings": {
"cache": {"edge_ttl": 86400},
"compression": {"mode": "auto"}
}
}'
curl -X PUT https://api.Sudun.com/v1/domains/example.com/policies/my-policy \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"settings": {
"cache": {"edge_ttl": 172800}
}
}'
curl -X GET https://api.Sudun.com/v1/domains/example.com/policies \
-H "Authorization: Bearer YOUR_API_KEY"
Need help with cache policies? Contact support@Sudun.com