Enable cache in an R2 bucket
To enable caching for a Cloudflare R2 bucket, make sure your bucket is public and accessible by the Cache. This can be done by creating a Custom Domain. Follow these steps to set up a Custom Domain for your bucket:
- Go to R2 and select your bucket.
- On the bucket page, select Settings.
- Under Public access > Custom Domains, select Connect Domain.
- Enter the domain name you want to connect to and select Continue.
- Review the new record that will be added to the DNS table and select Connect Domain.
This will generate a publicly available CNAME in the format [name].domain.com
.
By default Cloudflare will cache R2 content based on cache rules at the Edge only.
Tiered cache can be enabled by configuring Smart Tiered Cache which will select an Upper Tier data center next to your R2 bucket for optimal performance.
- Apply access controls to your newly public bucket. Refer to Control cache access with WAF and Snippets for more information.
- Be aware of the cacheable size limits for files.