o
odin.langpkg.dev
packages / library / ocache

ocache

v1.0.0library

No description provided.

No license · updated 1 day ago

ocache ⚡

ocache is a high-performance, zero-allocation, in-memory caching server written entirely in Odin.

Built to maximize throughput and minimize tail latencies, ocache bypasses the garbage collection spikes common in managed languages by using a fixed-capacity LRU engine and a custom binary wire protocol.

Features

  • Zero-Allocation LRU Engine: Once the cache reaches its maximum capacity, it recycles the oldest intrusive linked-list nodes for new data, ensuring $O(1)$ evictions and strictly flat memory usage.
  • ZEMP Binary Protocol: A custom 7-byte fixed-width wire protocol (Zero-overhead Exact Message Protocol) eliminates string parsing and branching overhead on the network layer.
  • Thread-Per-Connection: Leverages Odin's native threading to isolate client connections, maximizing multi-core OS utilization.
  • Built-in Tooling: Comes complete with a human-friendly CLI and a multithreaded benchmarking suite.

Getting Started

Prerequisites

You need the Odin Compiler installed and added to your system path.

Building

Clone the repository and run the included build script to compile the server and all companion tools heavily optimized for speed (-o:speed).

git clone [https://github.com/YOUR_USERNAME/ocache.git](https://github.com/YOUR_USERNAME/ocache.git)
cd ocache
build.bat all

(This will generate ocache_server.exe, ocache_cli_tool.exe, ocache_bench_tool.exe, and test_client_tool.exe in the root directory).

Usage

  1. Start the Server Run the server executable. It will immediately bind to 0.0.0.0:6969 and wait for connections
ocache_server.exe
  1. The CLI Tool Use the CLI to interact with the cahce manually.
ocache_cli_tool.exe set user:100 "Alice"
# OK

ocache_cli_tool.exe get user:100
# Alice
  1. The Benchmark Tool To verify the throughput claims on your own hardware, run the benchmark suite against a running server. It spawns multiple threads and floods the server with operations.
ocache_bench_tool.exe

Architecture

ocache is divided into three cleanly separated layers:

  1. Storage (src/lru.odin): A hash map paired with an intrusive doubly-linked list. Read/write locks allow highly concurrent reads, strictly locking only during writes or $O(1)$ node recyling.
  2. Protocol (src/zemp.odin): Uses strict little-endian integer framing. The server reads exactly 7 bytes to determine command routing and payload size, resulting in highly predictable socket reads.
  3. Network(src/main.odin): A thread-per-connection TCP listener that wraps raw sockets into custom Odin io.Stream interfaces.

License

MIT