CacheSniper is a Rust-based CLI tool for testing CDN caching behavior. It helps developers analyze Cache-Control, ETag, Last-Modified, and Expires headers to determine whether a webpage is being cached properly and how cache invalidation works.
- Parallel Scanning - Analyze multiple URLs at the same time
- Cache Validation (
--validate) - Ensures cache consistency - CDN-Specific Analysis - Parse Cloudflare (CF-Cache-Status), Fastly (X-Cache), and generic CDN headers
- Smart Cache Verdicts - Interprets cache status (HIT/MISS/DYNAMIC/BYPASS) with explanations
- CI/CD Integration -
--exit-codeflag returns exit code 1 when caching fails (perfect for pipelines) - JSON Output - Export cache test results in JSON format with all CDN headers
- Save Results to File - Use
--outputto store findings - CDN Detection - Automatically identifies 23+ CDN providers
- Prometheus Metrics - Monitor CDN caching behavior over time (requires Redis)
- Comprehensive Tests - 8+ unit tests covering CDN detection and cache validation
- Tabular & Colorized Output - Easy-to-read terminal display
Ensure you have Rust installed:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shThen, clone and build:
git clone https://github.com/CuriousLearner/cache_sniper.git
cd cache_sniper
cargo build --releaseTo install globally:
cargo install --path .Optional: Redis is only required if you want to use the --metrics flag for Prometheus monitoring. For basic cache checking, Redis is not needed.
Scan a single URL:
cache_sniper --url "https://example.com"cache_sniper --urls "https://example1.com" "https://example2.com"cache_sniper --url "https://example.com" --jsoncache_sniper --url "https://example.com" --json --output results.jsonRun a metrics server at http://localhost:9090/metrics:
cache_sniper --metricsNote: Metrics mode requires Redis to be running on localhost:6379. Install and start Redis:
# macOS
brew install redis
brew services start redis
# Ubuntu/Debian
sudo apt-get install redis-server
sudo systemctl start redis
# Other systems - see https://redis.io/downloadCheck if caching is working correctly by sending a normal request and a Cache-Control: no-cache request, then comparing responses:
cache_sniper --url "https://example.com" --validateHow it works:
- If
ETag,Last-Modified, and response do not change, cache is working correctly. ✅ - If values change, the cache might not be working consistently.
⚠️ - If no cache headers exist, validation is skipped automatically. 🚨
Use in CI pipelines to fail builds when caching is not properly configured:
# Fails with exit code 1 if caching is disabled or broken
cache_sniper --url "https://example.com" --exit-code
# Perfect for GitHub Actions, GitLab CI, CircleCI, etc.
cache_sniper --url "https://api.example.com" --validate --exit-code --jsonUse cases:
- Verify CDN configuration after deployment
- Ensure static assets are cacheable before merging PRs
- Monitor cache behavior in staging environments
CacheSniper understands CDN-specific headers and provides intelligent verdicts:
- CF-Cache-Status: HIT, MISS, EXPIRED, DYNAMIC, BYPASS, REVALIDATED
- CF-Ray: Request ID for debugging
- Example verdict:
"HIT - Served from Cloudflare cache"
- X-Cache: HIT, MISS
- X-Served-By: Cache server identifier
- X-Cache-Hits: Number of cache hits
- Age: Cache age in seconds
{
"url": "https://www.rust-lang.org",
"is_cached": true,
"cache_verdict": "HIT - Served from github cache",
"cdn_provider": "github",
"x_cache": "HIT",
"x_cache_hits": "1",
"age": "16",
"cache_control": "max-age=600",
"etag": "\"68f16b7d-4899\""
}🌍 Scanning: https://example.com
🌐 CDN Provider: Cloudflare
┌──────────────────┬───────────────────────────────┐
│ 🔍 Header ┆ 📜 Value │
╞══════════════════╪═══════════════════════════════╡
│ 🛠 Cache-Control ┆ max-age=86400 │
├──────────────────┼───────────────────────────────┤
│ 🔄 ETag ┆ "abc123" │
├──────────────────┼───────────────────────────────┤
│ 📆 Last-Modified ┆ Tue, 11 Mar 2025 06:28:07 GMT │
├──────────────────┼───────────────────────────────┤
│ ⏳ Expires ┆ None │
└──────────────────┴───────────────────────────────┘
✅ Success: This page is being cached!
🔍 CF-Cache-Status: HIT
⏱️ Age: 120 seconds
📊 Verdict: HIT - Served from Cloudflare cache🌍 Validating Cache for: https://example.com
🔄 ETag Before: "abc123"
🔄 ETag After : "abc123"
📆 Last-Modified Before: Tue, 11 Mar 2025 06:28:07 GMT
📆 Last-Modified After : Tue, 11 Mar 2025 06:28:07 GMT
⏳ Age Header: 86400
✅ Success: Cache is working correctly!If no cache headers are detected:
🚨 Warning: No caching detected on http://localhost:9001, skipping validation!CacheSniper helps:
- DevOps engineers debug caching behavior and identify stale content issues.
- SREs ensure cache invalidation works in CI/CD pipelines.
- Security teams detect cache poisoning vulnerabilities.
- Monitoring teams track real-time cache behavior via Prometheus.
MIT License. Use freely and contribute!