INTEGRITY Documentation

Enable cache in an R2 bucket

By default, R2 buckets are private. To serve R2 objects through Cloudflare's cache, you need to attach a domain name you control — called a Custom Domain — to the bucket. This creates a public URL backed by Cloudflare's network, so requests for your stored files go through Cloudflare's cache instead of hitting R2 directly every time.

Follow these steps to set up a Custom Domain for your bucket:

  1. Go to R2 and select your bucket.
  2. On the bucket page, select Settings.
  3. Under Public access > Custom Domains, select Connect Domain.
  4. Enter the domain name you want to connect to and select Continue.
  5. Review the new DNS record that will be added and select Connect Domain.

Cloudflare automatically adds a CNAME record that maps your domain to the bucket, generating a publicly available URL in the format [name].domain.com.

Tiered Cache

By default, Cloudflare caches R2 content at edge data centers (the data centers closest to visitors) based on cache rules. Each edge data center that gets a cache miss fetches content directly from R2.

Tiered Cache changes this by organizing data centers into a hierarchy. When a nearby data center has a cache miss, it first checks a designated upper-tier data center before going to R2. This reduces the number of requests that reach R2.

To enable Tiered Cache for R2, configure Smart Tiered Cache, which automatically selects the upper-tier data center with the lowest latency to your R2 bucket.

Additional considerations