How Caching Works
uv maintains a global cache that stores:- Downloaded wheels from package indexes
- Built wheels from source distributions
- Git repository clones
- Package metadata
- Python installations
The cache enables near-instant installations when packages have been previously downloaded or built.
Dependency Caching
Caching semantics vary by dependency type:- Registry Dependencies
- Direct URL Dependencies
- Git Dependencies
- Local Dependencies
From PyPI and other indexesuv respects HTTP caching headers:
Cache-ControlETagLast-Modified
Cache Commands
Clearing the Cache
clean
Removes all cache entries or entries for specific packages
prune
Removes only unused entries from previous uv versions
dir
Shows the cache directory path
Forcing Revalidation
Force uv to revalidate cached data:- --refresh
- --refresh-package
- --reinstall
Revalidates all cached data but uses cache for unchanged packages.
Local Directory Dependencies
Local directory dependencies passed explicitly are always rebuilt:Dynamic Metadata Caching
By default, uv rebuilds local directory dependencies only when:pyproject.toml,setup.py, orsetup.cfgchanges- A
src/directory is added or removed
Custom Cache Keys
Incorporate additional information into the cache key withtool.uv.cache-keys:
- Git Commit
- Additional Files
Rebuild on commit changes:
pyproject.toml
Glob Patterns
Use globs to track multiple files:pyproject.toml
Environment Variables
Invalidate cache on environment variable changes:pyproject.toml
Directory Existence
Track directory creation/removal:pyproject.toml
The
dir key only tracks directory creation/removal, not changes within the directory.Always Rebuild
Force always rebuilding specific packages:pyproject.toml
Cache Safety
Concurrent Access
It’s safe to run multiple uv commands concurrently:- Cache is thread-safe and append-only
- Robust to multiple concurrent readers and writers
- File-based locks prevent concurrent environment modifications
Lock Timeouts
Cache-modifying operations block while other uv commands run:Continuous Integration Caching
Optimize CI caching by storing only built wheels, not pre-built wheels.CI Cache Strategy
Why Prune Pre-built Wheels?
In CI environments:- Re-downloading pre-built wheels is often faster than restoring from cache
- Building from source is expensive and worth caching
uv cache prune --ciremoves pre-built wheels but keeps built-from-source wheels
Cache Directory
uv determines the cache directory in this order:- Temporary cache (if
--no-cachewas requested) - Explicit path from:
--cache-dirflagUV_CACHE_DIRenvironment variabletool.uv.cache-dirinpyproject.toml
- System default:
- Unix:
$XDG_CACHE_HOME/uvor$HOME/.cache/uv - Windows:
%LOCALAPPDATA%\uv\cache
- Unix:
View Cache Directory
Custom Cache Location
Performance Considerations
For best performance, the cache directory should be on the same filesystem as Python environments. This allows uv to use hard links instead of copying files.
Cache Versioning
The cache is organized into versioned buckets:Wheels
Built and downloaded wheel files
Source Distributions
Downloaded source distributions
Git Repositories
Cloned Git repositories
Metadata
Package metadata and manifests
Version Compatibility
Each bucket has a version number:- Breaking cache format changes increment the version
- Changes within a version are forwards and backwards compatible
- Multiple uv versions can safely share the same cache directory
Version Changes Example
uv 0.4.13 increased the metadata bucket version from v12 to v13:- uv 0.4.12 and 0.4.13 can share a cache directory
- The cache may contain duplicate metadata entries
- Old entries from v12 remain but are unused
Cleaning Old Versions
Remove unused bucket versions:Cache Deduplication
uv uses deduplication to minimize disk usage:Hard Links
On Unix systems, uv uses hard links:- Same file content referenced from multiple locations
- Zero additional disk space
- Requires cache and environment on same filesystem
Symbolic Links
For Python installations, uv uses symbolic links:- Points to the actual installation
- Enables transparent upgrades
- Links minor versions to specific patch versions
Fallback to Copy
When hard links aren’t available (different filesystems):- uv falls back to copying files
- Slower installation
- More disk usage
Cache Contents
The cache stores:Package Artifacts
- Wheels - Both downloaded and built from source
- Source distributions - Downloaded
.tar.gz,.zipfiles - Git clones - Repository checkouts at specific commits
Python Installations
- Managed Python versions - Downloaded interpreters
- Python executables - Installed to
~/.local/bin(Unix)
Metadata
- Package metadata - Version info, dependencies, markers
- Index metadata - PyPI and custom index data
- Resolution data - Cached dependency resolutions
Troubleshooting
Cache Issues
If experiencing cache-related problems:Disk Space
Monitor cache size:Stale Cache
For local dependencies, ensure cache keys are properly configured:pyproject.toml
Related Documentation
Projects
Learn about project environments and how they use the cache
Dependencies
Understand how dependencies are cached
Python Versions
Learn where Python installations are cached
CI/CD Integration
Optimize caching in continuous integration