• Home
Home
Anti-DDoS CDNStatic & dynamic acceleration, edge scrubbingAnti-DDoS IP forwardingL4 forwarding with protected IPsSDK game shieldClient SDK for gaming workloadsAnti-DDoS serversDedicated compute with high availabilityLearn more
Gaming solutionLow latency + protectionFinancial solutionCompliance & scrubbingLive streaming solutionPush/pull at the edgeBlockchain solutionWeb3 infra protectionExplore
DocumentationAPIs & onboardingHelp centerFAQs & ticketsBlog & newsUpdates & best practicesGlobal speed testMulti-region performance checksTag cloudTopic map across the siteOpen docs
AboutMission & visionCareersHiringPartnersEcosystemContactSales & supportContact us

Documentation

  • Introduction
  • Best Practices
Docs/Cache Configuration/Cache Rules

Cache Rules

速盾网络 Team
Docs

Tags

  • 缓存规则

On this page

No outline

Share

𝕏fin

Enterprise CDN & acceleration with AI-driven monitoring and full-spectrum, real-time DDoS/CC protection. Trusted by tens of thousands of companies for fast, secure, and reliable content delivery and DDoS mitigation.

Product

  • Anti-DDoS CDN
  • Anti-DDoS IP forwarding
  • SDK game shield
  • Anti-DDoS servers

Solutions

  • Gaming solution
  • Financial solution
  • Live streaming solution
  • Blockchain solution

Resources

  • Documentation
  • Help center
  • Blog & news
  • Global speed test

Company

  • About
  • Careers
  • Partners
  • Contact

© 2026-2028 sudun.com 保留所有权利

  • Privacy
  • Terms
  • Cookies

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.

How Caching Works

code
Request → Edge Server → Cache Check
                            │
                    ┌───────┴───────┐
                    │               │
               Cache HIT       Cache MISS
                    │               │
              Return cached    Fetch from origin
               content         Cache response
                               Return to user

Default Caching Behavior

By default, Sudun caches content based on:

Content TypeDefault TTLCacheable
Images (jpg, png, gif, webp)1 dayYes
CSS, JavaScript1 dayYes
Fonts (woff, woff2, ttf)1 dayYes
HTMLNot cachedNo
API responsesNot cachedNo

Creating Cache Rules

  1. Go to Domains → Select your domain
  2. Navigate to Caching → Cache Rules
  3. Click Create Rule

Rule Components

ComponentDescriptionExample
Match CriteriaConditions to match requestsURL path, file extension
Cache ActionHow to handle matched requestsCache, Bypass, Override
TTLTime to live in cache3600 (1 hour)

Match Criteria

URL Path Matching

code
# Exact match
/images/logo.png

# Prefix match
/static/*

# Wildcard match
/api/*/public

# Regex match (advanced)
^/blog/[0-9]{4}/.*$

File Extension Matching

Cache by file type:

json
{
  "match": {
    "file_extension": ["jpg", "jpeg", "png", "gif", "webp", "css", "js"]
  },
  "action": "cache",
  "ttl": 86400
}

Query String Matching

json
{
  "match": {
    "path": "/search",
    "query_string": {
      "contains": "category"
    }
  }
}

Header Matching

json
{
  "match": {
    "headers": {
      "Accept": "application/json"
    }
  },
  "action": "bypass"
}

Cache Actions

Cache

Store content at edge servers:

json
{
  "match": { "path": "/static/*" },
  "action": "cache",
  "ttl": 604800,
  "settings": {
    "browser_ttl": 86400,
    "serve_stale": true
  }
}

Bypass Cache

Always fetch from origin:

json
{
  "match": { "path": "/api/*" },
  "action": "bypass"
}

Override Origin Headers

Ignore origin cache headers:

json
{
  "match": { "path": "/assets/*" },
  "action": "override",
  "ttl": 2592000,
  "ignore_origin_headers": true
}

TTL Configuration

Edge TTL

How long content stays cached at edge servers:

ValueDurationUse Case
601 minuteFrequently updated content
36001 hourSemi-dynamic content
864001 dayStatic assets
6048001 weekRarely changing content
259200030 daysVersioned assets

Browser TTL

How long browsers cache content locally:

json
{
  "edge_ttl": 86400,
  "browser_ttl": 3600
}

Tip: Set browser TTL shorter than edge TTL to maintain control over cache invalidation.

Cache Key Configuration

The cache key determines what makes a cached object unique.

Default Cache Key

code
https://example.com/page?sort=date&page=1
         │            │        │
      Scheme       Path    Query String

Query String Handling

OptionBehavior
Include AllCache varies by all query params
Exclude AllIgnore query string for caching
Include SpecificOnly specified params affect cache
Exclude SpecificIgnore specified params

Example: Include specific parameters

json
{
  "cache_key": {
    "query_string": {
      "include": ["category", "page"]
    }
  }
}

Header-Based Cache Key

Vary cache by request headers:

json
{
  "cache_key": {
    "headers": ["Accept-Language", "Accept-Encoding"]
  }
}

Cookie-Based Cache Key

Vary cache by cookies (use sparingly):

json
{
  "cache_key": {
    "cookies": ["session_type", "user_tier"]
  }
}

Stale Content Handling

Serve Stale While Revalidate

Serve cached content while fetching fresh content:

json
{
  "serve_stale": {
    "while_revalidate": true,
    "on_error": true,
    "max_stale_age": 86400
  }
}

Stale-If-Error

Serve stale content when origin fails:

code
Origin Error (5xx) → Serve stale content → Log error

Respecting Origin Headers

By default, Sudun respects these origin headers:

HeaderBehavior
Cache-Control: max-age=XCache for X seconds
Cache-Control: no-cacheRevalidate before serving
Cache-Control: no-storeDo not cache
Cache-Control: privateDo not cache at edge
ExpiresCache until specified date
ETagEnable conditional requests

Override Origin Headers

Force caching regardless of origin headers:

json
{
  "match": { "path": "/static/*" },
  "action": "cache",
  "ttl": 86400,
  "respect_origin_headers": false
}

Rule Priority

Rules are evaluated in order. First matching rule wins:

code
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.

Common Cache Rule Patterns

Static Assets

json
{
  "name": "Static Assets",
  "match": {
    "file_extension": ["css", "js", "jpg", "png", "gif", "ico", "woff2"]
  },
  "action": "cache",
  "ttl": 2592000,
  "browser_ttl": 86400
}

API Responses

json
{
  "name": "API Bypass",
  "match": { "path": "/api/*" },
  "action": "bypass"
}

HTML Pages with Short TTL

json
{
  "name": "HTML Pages",
  "match": {
    "file_extension": ["html"],
    "path": "/*"
  },
  "action": "cache",
  "ttl": 300,
  "serve_stale": true
}

Versioned Assets (Long TTL)

json
{
  "name": "Versioned Assets",
  "match": {
    "path": "/assets/v*/*"
  },
  "action": "cache",
  "ttl": 31536000,
  "immutable": true
}

Debugging Cache Rules

Cache Status Header

Check the X-Cache-Status response header:

StatusMeaning
HITServed from cache
MISSFetched from origin
BYPASSCache was bypassed
EXPIREDCache expired, revalidating
STALEServed stale content

Test Cache Rules

bash
# Check cache status
curl -I https://example.com/static/style.css

# Response headers
X-Cache-Status: HIT
Cache-Control: max-age=86400
Age: 3600

API Reference

Manage cache rules via API:

bash
# 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