Content Cache

When your website receives traffic, every page request triggers work: the web server processes the request, the application executes code, the database runs queries. Even a simple page can take a few hundred milliseconds to generate, and complex pages take considerably longer. Under heavy load, those delays add up: pages slow down, servers get overwhelmed, visitors leave.

A content cache sits between your visitors and your application boxes. It stores copies of your web pages and serves them directly, without touching your application at all. Your site can handle several times more traffic while using fewer resources. The cache also acts as a shield: even if one of your application boxes goes down, the cache keeps serving pages from memory.

At freistilbox, we use Varnish for both content caching and load balancing. Varnish distributes incoming requests across your application boxes, monitors their health, and automatically routes around any box that stops responding. Your visitors never see error pages from a failed box.

Varnish

Varnish is a reverse proxy that sits in front of your web application. When a request comes in, Varnish checks if it already has a cached copy of the response. If it does, it serves that copy within microseconds. If not, Varnish forwards the request to one of your application boxes, stores the response in its cache, and sends it to the visitor.

If Varnish doesn’t have a cached copy yet, it forwards the request to one of your application boxes, stores the response, and sends it to the visitor.

sequenceDiagram
  participant Visitor
  participant Varnish
  participant App Box

  Visitor->>Varnish: Request
  Varnish->>App Box: Forward request
  App Box-->>Varnish: Response
  Varnish-->>Visitor: Response (stored in cache)

Once the response is cached, subsequent requests are served directly by Varnish — the application box is not involved at all.

sequenceDiagram
  participant Visitor
  participant Varnish
  participant App Box

  Visitor->>Varnish: Request
  Varnish-->>Visitor: Cached response (microseconds)

Varnish makes caching decisions based on HTTP headers. It respects standard cache control headers from your application, so you maintain full control over what gets cached and for how long. For content that changes frequently, you can set short cache lifetimes. For static assets like images and stylesheets, you can cache them for longer periods.


Table of contents