Skip to content

zcache is a simple, in-memory, low footprint, cache written in Zig.

License

Notifications You must be signed in to change notification settings

NiltonVolpato/zcache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

40 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

zcache

zcache demo

A simple, low-footprint, in-memory key-value cache with an auto-spawning daemon, written in Zig.

Features

  • 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.

Requirements

Zig 0.16.0-dev or newer (uses the new async I/O APIs).

Installation

zig build -Doptimize=ReleaseSafe install --prefix ~/

This installs the binary to ~/bin/zcache. Some prefer --prefix ~/.local/.

Usage

zcache status                  # Check server status
zcache get TABLE KEY           # Get a value
zcache set TABLE KEY VALUE     # Set a value

Options

  • -s, --silent - No output, use return code only
  • -r, --raw - Output raw value without formatting (for get)

Scripting

# 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"
fi

Development

zig build                                # Build to zig-out/bin/zcache
zig build run -- status                  # Build and run
zig build test                           # Run tests

Configuration

Optional 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.

About

zcache is a simple, in-memory, low footprint, cache written in Zig.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages