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:
| Level | How | Applies to |
|---|---|---|
| Query | cache: { duration } on createQuery, or --cache.duration on anfra query | That query |
| Data app | query.default.cache.duration on createApp | The app's queries |
| Project | query.default.cache.duration in .anfra/config.yml | Every 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 queryanswers withcache: whether it was ahit, 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.cacheholds the same. anfra cache statusshows 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'sTurning it off
- For the project:
query.cache.enabled: falsein.anfra/config.yml. - For one process, such as a CI run:
ANFRA_QUERY_CACHE_ENABLED=0.1turns it on even when the project setsfalse.
Where results are stored
Cached results live outside the project, under ~/.anfra/repos/<repo id>/cache/query/.