Edge response cache
Serve cacheable public GET responses from an edge network using Tyravel's ETag middleware (Tier 15) and your CDN or reverse proxy replay cache.
For Cloudflare-specific architecture (proxy + R2 + origin on Fly/Railway), start with the Cloudflare deployment guide.
App setup
Wrap safe, idempotent GET routes with HTTP cache middleware:
typescript
import { createHash } from 'node:crypto';
import { createHttpCacheMiddleware } from '@tyravel/http';
function hashBody(body: string): string {
return createHash('sha256').update(body).digest('hex');
}
Route.get('/posts/:slug', showPost, {
middleware: [
createHttpCacheMiddleware({
maxAge: 300,
etag: async (_request, body) => hashBody(body),
}),
],
});Tyravel emits ETag and honors If-None-Match with 304 Not Modified when content is unchanged.
Cloudflare (recommended pairing)
Typical stack: Node origin (Fly/Railway/Docker) + Cloudflare proxy in front.
- Orange-cloud your domain to the origin hostname.
- SSL mode: Full (strict).
- Add Cache Rules for public
GETroutes:
(http.request.method eq "GET" and starts_with(http.request.uri.path, "/posts/"))- Enable Origin Cache Control and respect
ETagrevalidation. - Create a Cache Rule bypass for
/dashboard/*,/api/me, and any route that setsSet-Cookie.
Cacheable vs bypass
| Route type | Edge cache? |
|---|---|
| Public blog post HTML | Yes — short max-age + ETag |
| Authenticated dashboard | Bypass |
| JSON API with personal data | Bypass |
Versioned assets (/build/*) | Yes — long max-age, fingerprinted filenames |
| WebSocket upgrade | Bypass (auto) |
Tiered cache
Enable Tiered Cache in Cloudflare to reduce origin load for global audiences. Origin still runs Tyravel SSR; edge serves repeat views of cacheable pages.
Fly.io
- Terminate TLS at Fly; run Tyravel with
prepareHttpServer()and warmed route/view caches. - Set
Cache-Controlon public responses. - Multiple machines do not need sticky sessions for cacheable GET routes.
- Dynamic session HTML: disable edge cache; use Tyravel
Cache.remember()at origin.
Railway / nginx
nginx
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=tyravel:10m;
location /public/ {
proxy_cache tyravel;
proxy_cache_valid 200 5m;
proxy_cache_revalidate on;
proxy_pass http://127.0.0.1:3000;
}Ensure Tyravel sends ETag so nginx can revalidate instead of serving stale content indefinitely.
Related
- Cloudflare deployment
- Deployment overview
- Cache —
Cache.remember()and Redis - Performance — boot profile and clustering