# Object cache

An object cache is an S3-compatible endpoint next to your servers that caches your buckets on local NVMe. Repeated reads come from the cache at local network speed, with no origin egress or request fees, and writes pass straight through to your own bucket.

It works with buckets on AWS S3, Cloudflare R2, Backblaze B2, Wasabi, MinIO and any other S3-compatible store.

## Create an object cache

1. Go to **Volumes** → **Object cache** and click **Create object cache**.
2. Enter a **Name**, for example `ml-models`.
3. Select the **Data center** your servers run in.
4. Select a **Plan** whose cache fits the data you read often. [Plans](#plans) lists their sizes.
5. Select the **Private network** of the servers that will use the cache.
6. To serve clients outside the private network, check **Allow public access**. For clients that can't reach IPv6, also check **Add a public IPv4 address**. It can't be added later.
7. Under **Buckets**, click **Add bucket**.
8. Select the **Provider** and enter your bucket's details:
    - **Bucket**: the bucket's name.
    - **Region**: the bucket's region. For Cloudflare R2, use `auto`. For Backblaze B2, use the region in the endpoint, like `us-west-004`.
    - **Endpoint**: the provider's S3 endpoint, an `https://` hostname.
    - **Access key ID** and **Secret access key**: a key that can read and write objects in this bucket only.
9. Click **Create object cache**.

![Create object cache form](https://imagedelivery.net/xZXo0QFi-1_4Zimer-T0XQ/ec3a4853-6eb7-4d12-d0e6-f0b9cf352300/md2x =2100x1832)

Before the cache is created, Better Stack checks that it can reach each bucket with the key you entered, so a wrong endpoint or key fails right away.

## Connect your apps

Open the cache in **Volumes** → **Object cache**. The **Connection** section shows its **Private endpoint**, its **Public endpoint** and the cache's own **Access key ID** and **Secret access key**. **Try it** has commands that list your first bucket with the AWS CLI.

- **Sign requests with the cache's keypair**, not your bucket's keys. Every request needs a signature, so nothing is readable without the keypair.
- **Use path-style addressing.** Any region string works.
- **Install nothing.** Point an app that speaks S3 at the cache's endpoint. SDK defaults work as they are.

```bash
[label Switch the AWS CLI to path-style addressing]
aws configure set default.s3.addressing_style path
```

For rclone, set `type = s3`, `force_path_style = true` and the cache's endpoint in the remote's config.

[info]
#### Mounting a bucket as a folder?
Use Mountpoint for Amazon S3 with its local cache off, or `rclone mount` with the default `--vfs-cache-mode off`. Avoid JuiceFS, ZeroFS and SeaweedFS: they hide your existing objects and add a second cache.
[/info]

## How caching works

- **Reads** are cached in 8 MiB slices, so a byte-range read, like a Parquet or ZIP file, never pulls the whole object.
- **Writes through the cache** are visible right away.
- **Writes made directly to your bucket** show up within the **Object TTL**, one day by default. To see them sooner, purge the cache.
- **Listings** are always live by default. Set a **Listing TTL** for list-heavy buckets that rarely change.
- **Eviction** keeps a re-read working set with **Least frequently used**, the default. Pick **Least recently used** for scan-style traffic where a hot set never re-forms.
- **If your origin goes down**, cached objects keep being served. Misses and writes return the origin's error.

## Write-through or write-back

By default, writes are **Write-through**, so a write is acknowledged once your bucket holds it.

With **Write-back**, a write is acknowledged once it's on the cache's NVMe, then uploaded to your bucket in the background. Failed uploads are retried until they succeed, and reads through the cache see your writes right away. Until the upload lands, the write exists only on the cache, so losing the cache loses it. Keep **Write-through** for data you can't re-create.

Write-back uses up to 10% of the capacity limit. When that fills up during a long origin outage, new writes fall back to write-through. Removing a bucket discards its writes that aren't uploaded yet, so stop writing and wait before you remove one.

## Manage a cache

Open the cache in **Volumes** → **Object cache** for these actions:

- **Add bucket** adds up to 20 buckets to one cache, from different providers side by side. **Served as** is the bucket name clients use. **Prefix view** exposes one prefix of the bucket as a whole bucket. Neither can change later.
- **Purge cache** drops cached objects of every bucket, one bucket or one prefix. Your buckets aren't touched.
- **Rotate credentials** creates a new keypair. The previous one keeps working for 24 hours, so you can update your clients without downtime.
- **Change plan** keeps the cache, with a brief interruption.

## Plans

| Plan | Cache | Cached objects |
|---|---|---|
| OP100 | 100 GB | 2 million |
| OP500 | 500 GB | 10 million |
| OP1000 | 1,000 GB | 20 million |

Many small objects can fill the object count before the cache size. The **Capacity limit** caps how much of the plan's cache you use, from 10 GB up to the full plan.

An object cache is billed per hour by plan, plus the public IPv4 address while you have one. Traffic on the private network is free, and cache misses are free ingress. Writes passed to your bucket and responses from the public endpoint count as internet egress.

## Limitations

- **One machine per cache.** If that machine fails, the cache is down until it's rebuilt, and the rebuilt cache starts empty.
- **No snapshots.** The cache only holds copies of your data.
- **Bucket endpoints** must be `https://` hostnames, not IP addresses.
- **Not supported:** copying objects between buckets on different providers, the S3 `DeleteBucket` call and browser form uploads.
- **Presigned URLs** from your origin don't work through the cache. Presigned URLs signed with the cache's keypair do.
- **Requests with customer-provided encryption keys** are never cached.

## Need help?

Please let us know at hello@betterstack.com.  
We're happy to help! 🙏
