> ## Documentation Index
> Fetch the complete documentation index at: https://defi-cli.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Config and Cache

> Configure precedence, retries/timeouts, and stale fallback semantics.

## Config precedence

`flags > env > config file > defaults`

Default config path:

```text theme={null}
${XDG_CONFIG_HOME:-~/.config}/defi/config.yaml
```

Minimal config example:

```yaml theme={null}
output: json
strict: false
timeout: 10s
retries: 2
cache:
  enabled: true
  max_stale: 5m
```

## Useful env vars

| Variable               | Purpose                          |
| ---------------------- | -------------------------------- |
| `DEFI_OUTPUT`          | `json` or `plain`                |
| `DEFI_TIMEOUT`         | Provider/planner request timeout |
| `DEFI_RETRIES`         | Retries per request              |
| `DEFI_MAX_STALE`       | Stale fallback window            |
| `DEFI_NO_STALE`        | Disable stale fallback           |
| `DEFI_NO_CACHE`        | Disable cache                    |
| `DEFI_CACHE_PATH`      | Cache DB path                    |
| `DEFI_CACHE_LOCK_PATH` | Cache lock path                  |

## Cache behavior

* Fresh cache hits (`age <= ttl`) return immediately.
* After TTL expires, CLI refetches providers.
* Stale data is served only when providers fail temporarily (`unavailable` or `rate_limited`) and within `max_stale`.
* Cache writes use SQLite WAL + busy timeout + lock/backoff retries to reduce lock contention in parallel runs.
* If cache init fails (path/permissions), commands continue with cache disabled.
* Metadata commands (`version`, `schema`, `providers list`, `chains list`) bypass cache initialization.

## Command TTLs

| Command                                                                                                                                                                | TTL   |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| `chains top`, `chains assets`, `protocols top`, `protocols categories`, `protocols fees`, `protocols revenue`, `dexes volume`, `stablecoins top`, `stablecoins chains` | `5m`  |
| `lend markets`, `yield opportunities`, `bridge list`, `bridge details`                                                                                                 | `60s` |
| `lend rates`, `lend positions`, `yield positions`                                                                                                                      | `30s` |
| `yield history`                                                                                                                                                        | `5m`  |
| `bridge quote`, `swap quote`                                                                                                                                           | `15s` |

Execution commands (`plan`, `run`, `submit`, `status`) and action inspection (`actions list|show|estimate`) bypass cache reads/writes.

## Strict mode

If any selected provider fails and partial results occur, `--strict` returns exit code `15` (`partial_results`).
