> ## Documentation Index
> Fetch the complete documentation index at: https://namespace.so/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# nsc cache bazel setup

Set up a remote Bazel cache.

Namespace provides high-performance Bazel caching with very low network latency between runners and the cache storage.
This allows your Bazel workflows to reuse build artifacts across runs, irrespective of your chosen granularity, significantly reducing build times.
`cache bazel setup` sets up a remote Bazel cache and generates a bazelrc to use it.

[Learn more about Bazel caching →](/docs/bazel/cache)

The cache can also serve as a [remote downloader](/docs/bazel/cache#remote-asset-api) for Bazel's external dependency fetches.

## Usage

```bash theme={null}
nsc cache bazel setup [--bazelrc <path>] \
    [--command <command>] \
    [--disable_build_events] \
    [--enable_remote_asset_api] \
    [--experimental_cache_name <name>] \
    [--experimental_direct] \
    [--output <plain|json>] \
    [--static] \
    [--static_token_duration <duration>] \
    [--token <path>]
```

### Example

The following example creates a remote Bazel cache and uses it during a build invocation.

<Steps titleSize="h4">
  <Step title="Configure the remote cache">
    Generate a Bazel configuration for the remote cache:

    ```bash theme={null}
    nsc cache bazel setup --bazelrc=/tmp/bazel-cache.bazelrc
    ```
  </Step>

  <Step title="Run a build">
    Use the generated configuration during a build:

    ```bash theme={null}
    bazel --bazelrc=yourown.bazelrc --bazelrc=/tmp/bazel-cache.bazelrc build //...
    ```
  </Step>
</Steps>

## Options

<h3 id="--bazelrc">
  \--bazelrc
</h3>

If specified, write the bazelrc to this path.

<h3 id="--command">
  \--command
</h3>

The Bazel command to use in the generated bazelrc (e.g. `build` or `common`). Defaults to `build`.

<h3 id="--disable_build_events">
  \--disable\_build\_events
</h3>

If specified, do not configure Bazel to send build events to Namespace.

<h3 id="--enable_remote_asset_api">
  \--enable\_remote\_asset\_api
</h3>

Opt in to the [remote asset API](/docs/bazel/cache#remote-asset-api), so Bazel can route external dependency fetches through the Namespace cache via `--experimental_remote_downloader`.

<h3 id="--experimental_cache_name">
  \--experimental\_cache\_name
</h3>

If specified, request a named experimental Bazel cache backing instance.

<h3 id="--experimental_direct">
  \--experimental\_direct
</h3>

Configure Bazel to connect directly to the cache endpoint with a freshly issued client certificate.

<h3 id="--static">
  \--static
</h3>

Use a static bearer token in `--remote_header` instead of a credential helper. Useful for CI/CD pipelines and automation without an interactive login.

<h3 id="--static_token_duration">
  \--static\_token\_duration
</h3>

The minimum duration of the static token configured. Requires `--static`. Defaults to `4h`.

<h3 id="-o---output">
  -o, --output
</h3>

Output format, one of `plain` or `json`. Defaults to `plain`.

<h3 id="--token">
  \--token
</h3>

Use the bearer token stored at this location for authentication instead of the default. Implies `--static`.
