A simple, low-footprint, in-memory key-value cache with an auto-spawning daemon, written in Zig.
- Auto-spawning daemon - The server starts automatically on first use and runs in the background. No manual setup required.
- Low memory footprint - The daemon uses less than 1MB of RAM on my machine.
- Multiple cache tables - Organize your cache into separate tables with independent size limits.
- LRU eviction - Least-recently-used entries are automatically evicted when a table is full.
- Configurable - Customize tables and server timeout via a simple config file.
Zig 0.16.0-dev or newer (uses the new async I/O APIs).
zig build -Doptimize=ReleaseSafe install --prefix ~/This installs the binary to ~/bin/zcache. Some prefer --prefix ~/.local/.
zcache status # Check server status
zcache get TABLE KEY # Get a value
zcache set TABLE KEY VALUE # Set a value-s, --silent- No output, use return code only-r, --raw- Output raw value without formatting (forget)
# Capture value in a variable
VALUE=$(zcache -r get default mykey)
# Check if key exists
if zcache -s get default mykey; then
echo "Key exists"
fizig build # Build to zig-out/bin/zcache
zig build run -- status # Build and run
zig build test # Run testsOptional config file at ~/.config/zcache.zon:
.{
.server_timeout_seconds = 3600,
.tables = &.{
.{ .name = "default", .maximum_size = 100 },
.{ .name = "sessions", .maximum_size = 50 },
},
}
The server shuts down after 8 hours of inactivity by default.
