Skip to content

Commit

Permalink
Document the cache directory
Browse files Browse the repository at this point in the history
  • Loading branch information
zanieb committed Aug 19, 2024
1 parent cc8fbed commit 130c318
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions crates/uv-cache/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub struct CacheArgs {

impl Cache {
/// Prefer, in order:
///
/// 1. A temporary cache directory, if the user requested `--no-cache`.
/// 2. The specific cache directory specified by the user via `--cache-dir` or `UV_CACHE_DIR`.
/// 3. The system-appropriate cache directory.
Expand Down
13 changes: 13 additions & 0 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,19 @@ pub enum CacheCommand {
/// Prune all unreachable objects from the cache.
Prune(PruneArgs),
/// Show the cache directory.
///
///
/// By default, the cache is stored in `$XDG_CACHE_HOME/uv` or `$HOME/.cache/uv` on Unix and
/// `{FOLDERID_LocalAppData}\uv\cache` on Windows.
///
/// When `--no-cache` is used, the cache is stored in a temporary directory and discarded when
/// the process exits.
///
/// An alternative cache directory may be specified via the `cache-dir` setting, the
/// `--cache-dir` option, or the `$UV_CACHE_DIR` environment variable.
///
/// Note that it is important for performance for the cache directory to be located on the same
/// file system as the Python environment uv is operating on.
Dir,
}

Expand Down
22 changes: 22 additions & 0 deletions docs/concepts/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,25 @@ pre-built wheels from the cache but retains any wheels that were built from sour
running `uv cache prune --ci` at the end of your continuous integration job to ensure maximum cache
efficiency. For an example, see the
[GitHub integration guide](../guides/integration/github.md#caching).

## Cache directory

uv determines the cache directory according to, in order:

1. A temporary cache directory, if `--no-cache` was requested.
2. The specific cache directory specified via `--cache-dir`, `UV_CACHE_DIR`, or
[`tool.uv.cache-dir`](../reference/settings.md#cache-dir).
3. A system-appropriate cache directory, e.g., `$XDG_CACHE_HOME/uv` or `$HOME/.cache/uv` on Unix and
`{FOLDERID_LocalAppData}\uv\cache` on Windows

!!! note

uv _always_ requires a cache directory. When `--no-cache` is requested, uv will still use
a temporary cache for sharing data within that single invocation.

In most cases, `--refresh` should be used instead of `--no-cache` — as it will update the cache
for subsequent operations but not read from the cache.

It is important for performance for the cache directory to be located on the same file system as the
Python environment uv is operating on. Otherwise, uv will not be able to link files from the cache
into the environment and will instead need to fallback to slow copy operations.
10 changes: 9 additions & 1 deletion docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -5568,7 +5568,15 @@ uv cache prune [OPTIONS]

### uv cache dir

Show the cache directory
Show the cache directory.

By default, the cache is stored in `$XDG_CACHE_HOME/uv` or `$HOME/.cache/uv` on Unix and `{FOLDERID_LocalAppData}\uv\cache` on Windows.

When `--no-cache` is used, the cache is stored in a temporary directory and discarded when the process exits.

An alternative cache directory may be specified via the `cache-dir` setting, the `--cache-dir` option, or the `$UV_CACHE_DIR` environment variable.

Note that it is important for performance for the cache directory to be located on the same file system as the Python environment uv is operating on.

<h3 class="cli-reference">Usage</h3>

Expand Down

0 comments on commit 130c318

Please sign in to comment.