anfra docsAlpha
Building blocks

Query cache

Answer repeated queries from your machine instead of the warehouse

The query cache keeps a query's result on your machine. The same query, run again within its cache duration, is answered from the cache instead of the warehouse. That saves time and warehouse cost when a data app reloads or an agent repeats a query.

A query uses the cache only when it sets a cache duration. With none, it runs on the warehouse.

What a duration means

A duration is both how old a result the query accepts and how long its own result is kept. A query that asks for 10m never gets a result older than 10 minutes, even if another query cached it with 1h.

A duration looks like 30s, 10m or 2h, at most 168h. 0s skips the cache. The project can lower that cap with query.cache.max_duration.

Where to set it

When several levels set a duration, the most specific wins:

LevelHowApplies to
Querycache: { duration } on createQuery, or --cache.duration on anfra queryThat query
Data appquery.default.cache.duration on createAppThe app's queries
Projectquery.default.cache.duration in .anfra/config.ymlEvery query, from any caller

The project's default applies to every caller, anfra query and the MCP server included. To cache only a data app's queries, set the app's default instead.

Seeing what the cache did

  • anfra query answers with cache: whether it was a hit, when the rows were read from the warehouse (cached_at), and when they expire (expires_at).
  • In a data app, the Inspect panel shows each query's hit or miss and age. result.debug.cache holds the same.
  • anfra cache status shows the cache's state, its folder, and how many results it holds.

If the cache isn't working, the query still runs on the warehouse, and its answer carries a cache_unavailable warning. Run anfra logs --event query_cache to see why.

Cleaning it

After you fix data in the warehouse, clean the cache. No result cached before the clean is used again:

anfra cache clean                                # every result
anfra cache clean --query.dataset ecommerce      # one dataset's
anfra cache clean --query.data-source warehouse  # one connection's

Turning it off

  • For the project: query.cache.enabled: false in .anfra/config.yml.
  • For one process, such as a CI run: ANFRA_QUERY_CACHE_ENABLED=0. 1 turns it on even when the project sets false.

Where results are stored

Cached results live outside the project, under ~/.anfra/repos/<repo id>/cache/query/.

On this page