Cloudflare Cache Reserve: Persistent Cache on R2 — Complete Guide
This tutorial covers Cloudflare Cache Reserve — a feature that combines the CDN edge cache with Cloudflare R2 object storage to create a persistent, multi-tier cache. You will learn how it differs from standard Caching, how it reduces origin load, and how to configure it.
Why Cache Reserve Matters
Standard CDN Caching has a fundamental limitation: when a file's TTL expires and no one requests it, the cached copy is evicted from the edge. The next request must go to the origin, causing a cache MISS. Cache Reserve solves this by storing a persistent copy in R2, Cloudflare's S3-compatible object storage. Even after edge TTL expires, the file is served from R2 instead of your origin. This eliminates cache misses for long-tail content and provides an additional layer of origin offload.
Real-world use: DodaZIP hosts millions of user-uploaded files. Most files are accessed rarely after the first upload. Standard Caching evicts these files after the TTL expires. Cache Reserve keeps them in R2 at a fraction of the cost of origin storage. When a user requests a year-old file, it is served from R2 at cache speed without touching the origin.
Cache Reserve Architecture
flowchart LR
A[Visitor] --> B[Cloudflare edge]
B --> C{Cached at edge?}
C -->|Yes| D[Serve from edge]
C -->|No| E{Cached in R2 Reserve?}
E -->|Yes| F[Serve from R2]
E -->|No| G[Fetch from origin]
G --> H[Store in R2 and edge]
H --> D
F --> D
style B fill:#f90,color:#fff
style E fill:#f90,color:#fff
Edge Cache vs Cache Reserve
# Standard edge cache flow
# Request 1: MISS -> Origin -> Store in edge (TTL: 1 hour)
# Request 2 (within 1 hour): HIT -> Serve from edge
# Request 3 (after 2 hours): EXPIRED -> MISS -> Origin again
# Cache Reserve flow
# Request 1: MISS -> Origin -> Store in edge + R2
# Request 2 (within 1 hour): HIT -> Serve from edge
# Request 3 (after 2 hours): EXPIRED -> R2 HIT -> Serve from R2
# Origin is never contacted again for this file
Configuring Cache Reserve
Enable Cache Reserve in Dashboard
Navigate to Caching > Cache Reserve in your Cloudflare dashboard. Toggle Cache Reserve on and select the R2 bucket to use for persistent storage.
# Enable Cache Reserve via API
curl -X POST "https://api.cloudflare.com/client/v4/zones/ZONE_ID/cache/cache_reserve" \
-H "Authorization: Bearer API_TOKEN" \
-H "Content-Type: application/json" \
--data '{
"value": "on"
}'
# Expected output:
# {"success":true,"result":{"id":"cache_reserve","value":"on"}}
Configure Cache Reserve with Custom Rules
You can combine Cache Reserve with Cache Rules to control which assets are eligible for R2 storage.
# Cache Rule to enable Cache Reserve for image assets
# URL pattern: *.example.com/images/*
# Cache Reserve: Eligible
# Edge TTL: 7 days
# This stores images in both edge cache (7 days) and R2 (persistent)
curl -sI https://example.com/images/photo.jpg | grep -i "cf-cache-status"
# Expected output:
# cf-cache-status: HIT
# cf-cache-reserve: HIT (served from R2 after edge expiry)
Cache Reserve Pricing
Cache Reserve uses R2's storage and Class B operations pricing model.
# R2 pricing for Cache Reserve (approximate)
# Storage: $0.015/GB/month
# Class B operations (write): $0.36/million requests
# Class A operations (read): $4.50/million requests
# Example: 500GB of cache reserve storage with 2M reads/month
# Storage cost: 500 * $0.015 = $7.50/month
# Read operations: 2 * $0.36 = $0.72/month
# Total: ~$8.22/month
# Compared to origin bandwidth for the same 500GB:
# Origin egress: 500GB * $0.09 = $45/month
# Savings: ~82%
Verifying Cache Reserve Headers
Cloudflare adds specific headers to responses served from Cache Reserve.
curl -sI https://example.com/images/background.jpg
# Expected headers when served from Cache Reserve after edge expiry:
# cf-cache-status: HIT
# cf-cache-reserve: HIT
# cf-ray: 7a2b3c4d5e6f7g8h
# age: 864000 (10 days — exceeded normal edge TTL)
FAQ
Practice Questions
- How does Cache Reserve differ from standard edge Caching in terms of data persistence?
- Why is Cache Reserve particularly valuable for long-tail content that is rarely accessed?
- What Cloudflare product provides the storage layer for Cache Reserve?
Summary
Cache Reserve extends Cloudflare's CDN Caching with persistent storage on R2. Files are stored in both the edge cache and R2 object storage. When the edge TTL expires, subsequent requests are served from R2 instead of the origin. This eliminates cache misses for all content after the first request and can reduce origin bandwidth costs by over 80%. Cache Reserve is ideal for large file libraries, media assets, and any content with long-tail access patterns.
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro — security-first tools for the modern web.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro