How Caching Works

Understand Barry’s automatic page caching strategy and its performance benefits.

How Caching Works

Here’s what happens behind the scenes when a route is first visited:

  1. User requests a page like /blog/my-post
  2. Barry checks if cache/blog/my-post/index.html exists
  3. If not, it runs index.server.go and renders index.html
  4. The result is saved to cache/blog/my-post/index.html
  5. Future requests serve this static file instantly
  6. The HTML is returned immediately to the user
  7. It is then saved to disk in the background, with locking to ensure safe writes

This approach combines dynamic rendering with static speed. If your page doesn’t need dynamic data, you don’t need to include a server file - just the HTML is enough. See Server Logic for dynamic route setup.