Skip to content

Add persistent metadata cache for binary resolution#22

Open
pirate wants to merge 4 commits intomainfrom
claude/package-manager-caching-46tSB
Open

Add persistent metadata cache for binary resolution#22
pirate wants to merge 4 commits intomainfrom
claude/package-manager-caching-46tSB

Conversation

@pirate
Copy link
Copy Markdown
Member

@pirate pirate commented Apr 10, 2026

Summary

This PR introduces a persistent on-disk JSON cache for binary resolution metadata, dramatically improving cold-start performance by avoiding redundant binary --version calls (~100ms each). For projects managing 20+ binaries, this reduces startup time from 2+ seconds to near-instant on cache hits.

Key Changes

  • New metadata_cache.py module: Implements BinaryMetadataCache class with:

    • get(): Retrieve cached (abspath, version, sha256) with validation
    • set(): Store resolved metadata with file fingerprinting (mtime + size)
    • invalidate(): Remove specific entries after install/update/uninstall
    • prune_stale(): Clean up entries for deleted/modified binaries
    • 7-day TTL with automatic expiration
    • File integrity checks to detect stale entries
  • Unified cache directory infrastructure in base_types.py:

    • New ABX_PKG_CACHE_DIR and DEFAULT_CACHE_DIR constants
    • New abx_pkg_cache_dir_default() function with env var precedence:
      1. ABX_PKG_<PROVIDER>_CACHE_DIR (most specific)
      2. ABX_PKG_CACHE_DIR / <provider>
      3. user_cache_path("abx-pkg") / <provider> (fallback)
  • Integration in binprovider.py:

    • load() checks persistent cache before expensive version resolution
    • install() and load() persist results to cache after successful resolution
    • invalidate_cache() clears both in-memory and persistent caches
  • Provider updates (pip, npm, uv, pnpm, bun, deno, yarn):

    • Replaced hardcoded USER_CACHE_PATH logic with abx_pkg_cache_dir_default()
    • Simplified cache directory initialization using Field(default_factory=...)
    • Added detect_cache_arg() validator to derive cache arguments per-instance
    • uv: Added --link-mode=hardlink for near-instant installs from cached wheels
  • Public API exports in __init__.py:

    • Exposed BinaryMetadataCache, metadata_cache, ABX_PKG_CACHE_DIR, and related utilities

Implementation Details

  • Thread-safety: Cache is not thread-safe but safe for concurrent processes (worst case is stale read/lost write, both harmless)
  • File fingerprinting: Uses (mtime, size) tuple to detect binary changes; allows 0.01s mtime tolerance for filesystem precision
  • Graceful degradation: All cache operations are advisory; callers always fall back to live resolution on cache miss
  • Atomic writes: Uses temp file + rename pattern to prevent corruption
  • Error handling: Silently ignores cache I/O errors; cache is purely a performance optimization

https://claude.ai/code/session_018Jkv9vUDZyMqE5AYY1r9Fh


Open with Devin

Summary by cubic

Adds a persistent on-disk metadata cache for binary resolution and unifies provider download caches, cutting cold-start time by avoiding repeated --version calls and enabling faster installs from shared caches.

  • New Features

    • Added BinaryMetadataCache (JSON store with 7-day TTL, mtime+size validation, malformed-entry guards, atomic writes).
    • Integrated cache into load()/install()/update(); invalidate_cache() now clears in-memory and on-disk entries.
    • Enabled uv with --link-mode=hardlink for near-instant installs from cached wheels.
    • Exported BinaryMetadataCache, metadata_cache, ABX_PKG_CACHE_DIR, DEFAULT_CACHE_DIR, abx_pkg_cache_dir_default.
  • Refactors

    • Unified cache dir: ~/.cache/abx-pkg/<provider> with env precedence ABX_PKG_<PROVIDER>_CACHE_DIR > ABX_PKG_CACHE_DIR > default.
    • Updated pip, npm, pnpm, yarn, bun, deno, uv to use the unified cache and derive cache args per instance; updated uv.lock.
    • Updated README with cache-directory controls, env var precedence, and new provider defaults.

Written for commit 3e415d4. Summary will update on new commits.

…S optimizations

Consolidate all provider download caches under a single ABX_PKG_CACHE_DIR
(~/.cache/abx-pkg/<provider>) instead of scattered per-provider tempdir
locations. This mirrors the ABX_PKG_LIB_DIR pattern for install_roots and
enables cross-install_root cache sharing — uv/pnpm automatically hardlink
from their global CAS into per-install_root directories, giving near-instant
installs for previously-downloaded packages.

Key changes:
- Add ABX_PKG_CACHE_DIR + abx_pkg_cache_dir_default() to base_types.py
- Add BinaryMetadataCache: persistent on-disk JSON cache that stores resolved
  binary metadata (abspath, version, sha256) validated by file mtime+size,
  avoiding ~100ms --version subprocess calls on repeated load() across process
  restarts
- Enable uv --link-mode=hardlink by default (hardlinks from CAS to venvs)
- Update all 7 providers (pip, uv, npm, pnpm, yarn, bun, deno) to use
  unified cache directory with proper env var override support
  (ABX_PKG_<PROVIDER>_CACHE_DIR > ABX_PKG_CACHE_DIR > default)

https://claude.ai/code/session_018Jkv9vUDZyMqE5AYY1r9Fh
cubic-dev-ai[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

claude added 2 commits April 10, 2026 23:33
… update()

- Fix pyright reportReturnType in _load(): validate json.loads result
  is a dict before assigning to self._data
- Guard cached_at type in get() and prune_stale() to handle malformed
  cache entries without raising TypeError
- Add metadata_cache.set() call to update() so the first load() after
  an update gets a cache hit instead of falling through to the slow
  --version subprocess path
- Apply ruff-format auto-fixes

https://claude.ai/code/session_018Jkv9vUDZyMqE5AYY1r9Fh
devin-ai-integration[bot]

This comment was marked as resolved.

…ults

- Add cache-directory controls table documenting ABX_PKG_CACHE_DIR and
  ABX_PKG_<PROVIDER>_CACHE_DIR env vars with precedence rules
- Update all 7 provider code blocks to show new cache_dir defaults
  (abx_pkg_cache_dir_default("<provider>") -> ~/.cache/abx-pkg/<provider>)
- Update UvProvider to show uv_install_args = ["--link-mode=hardlink"]

https://claude.ai/code/session_018Jkv9vUDZyMqE5AYY1r9Fh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants