| Crates.io | cacher |
| lib.rs | cacher |
| version | 0.4.3 |
| created_at | 2025-05-30 19:42:08.640689+00 |
| updated_at | 2025-05-31 21:22:02.705866+00 |
| description | A CLI tool for caching command outputs |
| homepage | |
| repository | https://github.com/deanshub/cacher |
| max_upload_size | |
| id | 1695609 |
| size | 88,860 |
A command-line tool for caching command outputs to save time when running repetitive commands.
You can download pre-built binaries for your platform from the latest GitHub release:
After downloading, make the binary executable (Linux/macOS):
chmod +x cacher-*
# Clone the repository
git clone https://github.com/deanshub/cacher.git
cd cacher
# Build the project
cargo build --release
# Optional: Install the binary
cargo install --path .
cargo install cacher
# Basic usage
cacher run "ls -la"
# With TTL (time-to-live) in seconds
cacher run "ls -la" --ttl 3600
# Force execution (ignore cache)
cacher run "ls -la" --force
cacher list
# Clear all cache
cacher clear --all
# Clear specific command
cacher clear --command "ls -la"
cacher hash "ls -la"
You can create a .cacher file in your project to customize caching behavior. Cacher will automatically look for this file in the current directory and its parent directories.
# Default settings for all commands
default:
ttl: 3600 # Default TTL in seconds (1 hour)
include_env:
- PATH
- NODE_ENV # Include environment variables in cache key
Use glob patterns to match commands:
commands:
- pattern: "npm run *" # Matches all npm run commands
ttl: 7200 # 2 hours
- pattern: "git status" # Exact match
ttl: 60 # 1 minute
Specify files that should invalidate the cache when modified:
commands:
- pattern: "npm run build"
depends_on:
- file: "package.json" # Single file
- files: "src/**/*.js" # Glob pattern for multiple files
Include specific environment variables in the cache key:
commands:
- pattern: "docker-compose up"
include_env:
- DOCKER_HOST
- COMPOSE_PROJECT_NAME
Only consider specific lines in files using regex patterns:
commands:
- pattern: "npm run dev"
depends_on:
- lines:
file: ".env"
pattern: "^(API_|DEV_)" # Only match lines starting with API_ or DEV_
Cache directories or files produced by commands:
commands:
- pattern: "npm run build"
artifacts:
- type: "directory"
path: "dist" # Cache the dist directory
- pattern: "docker build -t myapp ."
artifacts:
- type: "docker_image"
name_from: "argument"
position: 1 # Extract from the -t argument
# Default settings for all commands
default:
ttl: 3600 # Default TTL in seconds
include_env:
- PATH
- NODE_ENV
# Command-specific settings
commands:
# Cache npm build commands for 2 hours
- pattern: "npm run build"
ttl: 7200
include_env:
- NODE_ENV
depends_on:
- files: "src/**/*.{js,jsx,ts,tsx}" # All source files
- files: "package*.json" # package.json and package-lock.json
- file: "tsconfig.json" # Specific file
# Cache docker-compose commands for 1 day
- pattern: "docker-compose up *"
ttl: 86400
include_env:
- DOCKER_HOST
depends_on:
- file: "docker-compose.yml"
- files: "Dockerfile*"
- lines:
file: ".env"
pattern: "^(DB_|API_)" # Only consider DB_ and API_ variables
artifacts:
- type: "directory"
path: "node_modules" # Cache node_modules directory
Cacher uses SHA-256 hashing to generate unique identifiers for each command. When you run a command through Cacher, it:
When retrieving a cached command, Cacher will:
The cache is stored in your system's cache directory:
~/Library/Caches/cacher/~/.cache/cacher/C:\Users\{username}\AppData\Local\cacher\cargo test
cargo doc --open
This project is licensed under the MIT License - see the LICENSE file for details.