Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Caching Middlewares

  • cache — in-memory response caching with TTL

cache

Caches responses in memory with TTL support.

x-barbacane-middlewares:
  - name: cache
    config:
      ttl: 300
      vary:
        - Accept-Language
        - Accept-Encoding
      methods:
        - GET
        - HEAD
      cacheable_status:
        - 200
        - 301

Configuration

PropertyTypeDefaultDescription
ttlinteger300Cache duration (seconds)
varyarray[]Headers that vary cache key
methodsarray["GET", "HEAD"]HTTP methods to cache
cacheable_statusarray[200, 301]Status codes to cache

Cache key

Cache key is computed from:

  • HTTP method
  • Request path
  • Vary header values (if configured)

Cache-Control respect

The middleware respects Cache-Control response headers:

  • no-store — Response not cached
  • no-cache — Cache but revalidate
  • max-age=N — Use specified TTL instead of config