Add persistent metadata cache for binary resolution#22
Open
Conversation
…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
… 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
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a persistent on-disk JSON cache for binary resolution metadata, dramatically improving cold-start performance by avoiding redundant
binary --versioncalls (~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.pymodule: ImplementsBinaryMetadataCacheclass with:get(): Retrieve cached (abspath, version, sha256) with validationset(): Store resolved metadata with file fingerprinting (mtime + size)invalidate(): Remove specific entries after install/update/uninstallprune_stale(): Clean up entries for deleted/modified binariesUnified cache directory infrastructure in
base_types.py:ABX_PKG_CACHE_DIRandDEFAULT_CACHE_DIRconstantsabx_pkg_cache_dir_default()function with env var precedence:ABX_PKG_<PROVIDER>_CACHE_DIR(most specific)ABX_PKG_CACHE_DIR / <provider>user_cache_path("abx-pkg") / <provider>(fallback)Integration in
binprovider.py:load()checks persistent cache before expensive version resolutioninstall()andload()persist results to cache after successful resolutioninvalidate_cache()clears both in-memory and persistent cachesProvider updates (pip, npm, uv, pnpm, bun, deno, yarn):
USER_CACHE_PATHlogic withabx_pkg_cache_dir_default()Field(default_factory=...)detect_cache_arg()validator to derive cache arguments per-instance--link-mode=hardlinkfor near-instant installs from cached wheelsPublic API exports in
__init__.py:BinaryMetadataCache,metadata_cache,ABX_PKG_CACHE_DIR, and related utilitiesImplementation Details
https://claude.ai/code/session_018Jkv9vUDZyMqE5AYY1r9Fh
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
--versioncalls and enabling faster installs from shared caches.New Features
BinaryMetadataCache(JSON store with 7-day TTL, mtime+size validation, malformed-entry guards, atomic writes).load()/install()/update();invalidate_cache()now clears in-memory and on-disk entries.uvwith--link-mode=hardlinkfor near-instant installs from cached wheels.BinaryMetadataCache,metadata_cache,ABX_PKG_CACHE_DIR,DEFAULT_CACHE_DIR,abx_pkg_cache_dir_default.Refactors
~/.cache/abx-pkg/<provider>with env precedenceABX_PKG_<PROVIDER>_CACHE_DIR>ABX_PKG_CACHE_DIR> default.pip,npm,pnpm,yarn,bun,deno,uvto use the unified cache and derive cache args per instance; updateduv.lock.Written for commit 3e415d4. Summary will update on new commits.