Once: Cache CLI Commands
The "once" CLI tool allows you to execute a command once and reuse its output for a specified period. When you run a command with "once," it executes the command in your current directory and stores the standard output in memory within a background daemon. Subsequent calls to the same command, directory, and tenant key within 8 hours will retrieve the cached output instead of re-running the command. The daemon automatically stops when all cached entries expire.
Typically, "once" is used to read secrets like those from 1Password without repeatedly authenticating with a fingerprint. By running "once" once, subsequent calls within an 8-hour window won't require the fingerprint for authentication.
To set up "once," you can create a configuration file named "mise.local.toml" and specify options and commands in it. The tool supports various formatting options for the --until flag to set the expiration time of the cached entry. The default working directory is included in the cache key, but you can exclude it using the --no-dir flag for commands with directory-independent outputs.
The cache key is generated using an HMAC-SHA256 hash of the tenant key, working directory, command, and arguments. The tenant key serves as a namespace and is not meant to be kept secret. Multiple terminals can share the same cache by using a fixed tenant key.
The daemon runs in a secure, user-specific directory with restricted permissions, ensuring that other users cannot access the cache. The cache is stored in a socket accessible only to the user running "once." By default, the working directory is part of the cache key, but you can use the --no-dir flag for commands with directory-independent outputs.
Written by urgent.news from Hacker News's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.