Static HTML Caching

Pages are rendered once, cached to disk, and served instantly on future requests.

Caching

Barry uses static HTML caching to serve your site with the speed of a static host, while retaining the flexibility of dynamic rendering. Once a page is rendered for the first time, it is stored in a cache/ directory and reused on subsequent requests - bypassing server logic for maximum performance.

Why Caching Matters

Barry turns dynamic routes into fast, static HTML. When a user hits a route for the first time, Barry runs your index.server.go, injects the data into index.html, and writes the final HTML into the cache/ directory. All subsequent requests serve that static file.

This delivers near-CDN performance without needing to prebuild your whole site.

Benefits

  • Performance: Pages load instantly after first render
  • Efficiency: Go logic only runs once per route (unless cache is cleared)
  • Scalability: Cached pages reduce server load under high traffic
  • Non-blocking: On cache miss, pages are rendered and returned immediately — saving happens in the background

You can remove cache entries manually or with the CLI. Learn more in barry clear.

Concurrency Safety

Barry uses file-based locking to prevent multiple requests from writing to the same cache path at once. This ensures that even under heavy load, routes are only written once per cache miss without race conditions.