Skip to content

Response Filesystem Cache

Stores anonymous responses for registered paths as files and serves repeat requests from those files instead of running the route. Cache tags decide when a file stops being served.

For Drupal 10.6, 11.3+ and 12

my_module.response_cache.yml
products:
  path_prefix: /api/products
  query_allowlist:
    - category
    - page

What it does

A module registers a path prefix. The first anonymous request for a path under it runs the route as usual, and the response is written to a file beneath public://response_filesystem_cache/. Later anonymous requests for the same path, host, language and allowed query are answered from that file until one of the response's cache tags is invalidated, its max-age passes, or the cache is rebuilt.

It is for read-only endpoints, such as JSON APIs, whose responses are the same for every anonymous visitor and are costly to build. Signed-in visitors always get the live route. Requests still boot Drupal; the cache saves the route's work, not the bootstrap.

The Response Filesystem Cache settings form, listing three mappings from an Example API module with their path prefixes, allowed query parameters, file limits and storage directories. Two are enabled and one is turned off.

Site administrators can turn each registered mapping off at Configuration > Development > Response Filesystem Cache.

Who it is for

Developers of modules that expose anonymous, read-only endpoints. The module does nothing until a module ships a MODULE.response_cache.yml file, and it caches only responses that pass every check in Usage.