CLI: Cache Management
Relevant source files
The following files were used as context for generating this wiki page:
The Cache Management system in the regxa CLI provides a set of tools to maintain, inspect, and clear the local storage used by the library. Since regxa queries multiple package registries, it employs a storage-backed cache decorated with a lockfile to ensure data freshness and integrity while improving performance for repeated lookups.
The cache system is designed as an optional decorator layer (via CachedRegistry) that wraps standard registry operations. The CLI exposes these internals through the cache subcommand, allowing users to view the cache directory, check the status of cached entries, prune stale data, or wipe the cache entirely.
Sources: README.md, src/cache/AGENTS.md:5-10, src/commands/cache.ts:8-12
Cache Command Architecture
The cache commands are implemented using the citty framework and are registered as subcommands under the primary cache command. These commands interact with three main components of the cache subsystem: the Lockfile, the Storage provider, and Path resolution.
The diagram shows the delegation of CLI subcommands to specific modules within the cache subsystem.
Sources: src/cli.ts:16, src/commands/cache.ts:8-12, src/cache/AGENTS.md:12-18
Available Subcommands
The cache command group provides four primary operations for managing the local environment.
| Subcommand | Description | Relevant Module |
|---|---|---|
clear | Removes all cached data and resets the lockfile to version 1. | src/cache/storage.ts |
path | Prints the absolute path to the OS-specific cache directory. | src/cache/paths.ts |
status | Displays entry counts, freshness statistics, and per-ecosystem breakdowns. | src/cache/lockfile.ts |
prune | Removes entries that have exceeded their Time-To-Live (TTL). | src/cache/lockfile.ts |
Sources: src/commands/cache.ts:13-75, src/cache/AGENTS.md:20-25
Cache Status and Freshness
The status command reads the lockfile to calculate the health of the cache. An entry is considered "fresh" if the current time is less than the timestamp it was fetched at plus its specific TTL.
Sequence of operations for determining cache freshness during a status check.
Sources: src/commands/cache.ts:35-50, test/unit/lockfile.test.ts:71-100
Internal Logic and Data Flow
TTL Policies
The CLI follows project-wide freshness policies defined in the lockfile module. These values determine how long different types of package metadata remain valid before the CLI considers them stale.
| Data Type | TTL (Seconds) | Duration |
|---|---|---|
| Package Metadata | 3600 | 1 Hour |
| Version List | 1800 | 30 Minutes |
| Dependencies | 86400 | 24 Hours |
| Maintainers | 86400 | 24 Hours |
Sources: test/unit/lockfile.test.ts:18-23, README.md
Integrity and Pruning
The prune command invokes the pruneStale logic, which iterates through the lockfile and removes any entry where isFresh(entry) returns false. This ensures that the local storage does not grow indefinitely with outdated metadata. Additionally, the cache subsystem uses SHA-256 integrity checks; if the stored data does not match the hash in the lockfile, the system triggers a re-fetch regardless of TTL.
The logic flow for the cache pruning process.
Sources: src/commands/cache.ts:68-75, src/cache/lockfile.ts:160-185, README.md
Storage and Path Resolution
The path command utilizes getCacheDir() to provide transparency regarding where data is stored. The system follows platform-specific conventions:
- Linux:
~/.cache/regxa(XDG) - macOS:
~/Library/Caches/regxa - Windows:
%LOCALAPPDATA%\regxa\cache
Users can override this location using the REGXA_CACHE_DIR environment variable.
Sources: src/cache/paths.ts, README.md, src/commands/cache.ts:28-33
Summary
The CLI Cache Management system provides users with essential visibility and control over the local metadata lifecycle. By abstracting the complex interactions between unstorage drivers, lockfile TTL policies, and SHA-256 integrity checks into simple subcommands like status and prune, regxa ensures that users can maintain a performant and accurate local environment for package registry queries.