# CDN and caching

> How public and private files are cached, and how a change reaches visitors.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://files.docs.sypnia.com/images/cdn-and-caching/

For agents: Files caching: own address via Sypnia Domains (connect cdn.<domain> files:<bucket>, public files, transforms and signed URLs; API stays on its host; use a files-only subdomain); public files at edge shared (bucket cacheControl, default 1 h); public transforms 30 days keyed by options; private via signed URL cached per URL until expiry; private via token not cached; upsert invalidates cached copies and transforms; versioned paths recommended; Range requests for video seeking; ETag/If-None-Match.

| File                       | Cached where                    | For how long                                   |
| -------------------------- | ------------------------------- | ---------------------------------------------- |
| public file                | at the edge, shared by everyone | the bucket's `cacheControl`, 1 hour by default |
| public image transform     | at the edge                     | 30 days, keyed by the options                  |
| private file by signed URL | at the edge, for that URL only  | until the URL expires                          |
| private file by token      | not cached at the edge          | —                                              |

Replacing a file (`upsert`) invalidates its cached copies and its transforms. Clients that cache harder should use paths with a version (`menu/v3/pan.jpg`).

Range requests (`Range: bytes=…`) are supported, so video players can seek. `ETag` and `If-None-Match` make repeat requests cheap.

## Your own address

Public files and image transforms are served on `<ref>.files.sypnia.app` from the start. To serve them on your own domain, connect an address with [Sypnia Domains](https://domains.docs.sypnia.com/connect/data-and-files):

```bash
npx @sypnia/domains connect cdn.laespiga.co files:public
```

Domains writes the record and the certificate, and the same files answer on `https://cdn.laespiga.co/menu/pan.jpg`. Signed links can use the address too; the Files API stays on its own host. Use a subdomain made only for files, never the one your app runs on, so an uploaded file can never read your app's cookies. A domain registered somewhere else connects the same way once Domains keeps its DNS ([DNS only](https://domains.docs.sypnia.com/dns/dns-only-and-registration-only)).
