Nylon Mesh

SSR & Frontend Caching

Understand the 2-tier cache architecture, bypass rules, and Cache-Control injection.

Nylon Mesh is purpose-built to absorb repetitive traffic spikes that would normally overwhelm SSR Node.js applications. It acts as an unbreakable Stale Shield using a tiered caching architecture.

Cache Tiers

Tier 1 — Local Memory (RAM)

The first layer of defense. Caches rendered HTML payloads and static files directly in the proxy's RAM using Moka:

PropertyDescriptionExample
tier1_capacityMax elements (pages/files) held concurrently10000
tier1_ttl_secondsTime-to-Live — proxy serves from RAM during this interval35

Performance

Set TTL to 35 seconds for high-traffic environments. This prevents backend melting while keeping data near real-time.

Tier 2 — Redis (Distributed)

A persistent, distributed cache layer backing up Tier 1:

PropertyDescriptionExample
redis_urlRedis connection stringredis://localhost:6379
tier2_ttl_secondsGeneral TTL for cached pages60
statusHTTP status codes to cache[200, 404]
content_typesHTTP Content-Types to cache["text/html"]

How the Stale Shield Works

When 1,000 users request the homepage simultaneously:

  1. Proxy checks Tier 1 (RAM) → First request MISSES
  2. Proxy checks Tier 2 (Redis) → First request MISSES
  3. Proxy hits your Next.js / Nuxt server ONCE
  4. The remaining 999 requests are served instantly from Tier 1 RAM — never reaching Node.js

Warning

By default, only text/html responses with HTTP 200 status are cached. You can override this using the cache.status and cache.content_types config fields. API endpoints and non-GET methods are automatically excluded.


Clearing the Cache

Since Tier 2 cache is stored in Redis, you can manually clear the cache using standard Redis commands via redis-cli.

Nylon Mesh stores cached pages in Redis Hashes (HSET). The Redis key is the Hostname (e.g., 127.0.0.1:3000 or example.com), and the hash field is the URI/Path (plus encoding).

Clear Entire Cache

To purge all cached pages across all applications sharing the Redis instance:

redis-cli FLUSHALL

Clear an Entire Domain/Host

To clear all cache for a specific hostname (e.g. example.com or localhost:3000), you can simply delete the hash key:

redis-cli DEL "127.0.0.1:3000"

Clear Specific Page

If you want to clear a specific cached page, you must delete its hash fields (the path and the headers) under the host key. Note that if compression is used, you may need to delete the encoded variants (e.g., /about:gzip).

redis-cli HDEL "127.0.0.1:3000" "/about" "/about:headers" "/about:gzip" "/about:gzip:headers"

Cache Bypass

In frontend frameworks, you have static pages (home, blogs) and dynamic systems (APIs, dashboards). Prevent Nylon from caching dynamic paths:

bypass:
  paths:
    - "/_next/webpack-hmr" # Next.js HMR (dev only)
    - "/api/"              # Backend API calls
    - "/admin/"            # Authenticated panels
  extensions:
    - ".ico"               # Skip favicons

Important

Bypass rules have absolute priority. If a user hits /api/users, the proxy ignores all caching and forwards directly to the backend.


Cache-Control Header Injection

Modern frameworks bundle CSS, JS, and images with unique hashes (e.g., _next/static/css/hash.css). These files never change and should be cached permanently by the browser.

Use Nylon Mesh to inject Cache-Control headers dynamically:

cache_control:
  - value: "public, max-age=31536000, immutable"
    paths:
      - "/_next/static/"  # Next.js hashed assets
      - "/_nuxt/"         # Nuxt.js assets
    extensions:
      - ".png"
      - ".jpg"
      - ".svg"

This tells the browser: "Keep these static files for a year. Don't ask the server again."

On this page