# Plan a Buildx cache step

Coming soon. Planned worked example, not available yet in production.

## Before you start

Planned workflow: Docker cache is not available in production. This example needs a Dockerfile and future authorized cache delivery. Saving a preference does not turn caching on. Without RZV_DOCKER_CACHE_DIR the example builds cold.

## Planned example

YAML · planned

```yaml
steps:
  - name: Build with local layer cache
    shell: bash
    run: |
      set -euo pipefail
      cache="${RZV_DOCKER_CACHE_DIR:-}"
      builder="rzv-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
      docker buildx create --name "$builder" --driver docker-container
      trap 'docker buildx rm --force "$builder"' EXIT
      args=()
      if [[ -n "$cache" ]]; then
        rm -rf -- "$cache/next"
        args+=(--cache-to "type=local,dest=$cache/next,mode=max")
        if [[ -f "$cache/current/index.json" ]]; then
          args+=(--cache-from "type=local,src=$cache/current")
        fi
      fi
      docker buildx build --builder "$builder" --progress=plain \
        "${args[@]}" \
        --load --tag example:ci .
      if [[ -n "$cache" ]]; then
        rm -rf -- "$cache/current"
        mv -- "$cache/next" "$cache/current"
      fi
```

## Review and protect your work

Once caching is available, repeat an unchanged build on the same trusted ref and host and inspect the CACHED output. Changed inputs rebuild. A different host or eviction sometimes produces a cold build. The design keeps fork pull requests and other untrusted jobs out of any cache that trusted builds read. Export only once per job. No speedup or cache reuse across hosts is promised. No price has been announced.

## Related pages

[Feature guide](https://runzivo.dev/docs/docker-layer-cache/)

On this page and page tools
