How I Built a 350,000+ ops/s Cache for PHP on Windows Using Rust and FFI
The Story Behind NitroCache As a PHP developer working on Windows, I've always struggled with the overhead of Redis and Memcached in local environments. Running Docker or WSL2 just to have a fast k...

Source: DEV Community
The Story Behind NitroCache As a PHP developer working on Windows, I've always struggled with the overhead of Redis and Memcached in local environments. Running Docker or WSL2 just to have a fast key-value store felt like overkill. I wanted something native, lightweight, and incredibly fast. So, I decided to build NitroCache. 🦀 Why Rust? I chose Rust for the core engine because I needed: Memory Safety: Handling shared memory segments can be dangerous; Rust makes it predictable. Performance: I wanted to achieve near-zero latency. FFI Compatibility: Rust makes it easy to export C-compatible functions that PHP can call via the FFI extension. 🚀 The Architecture: Bypassing the Network Stack Standard caching solutions use TCP/IP sockets. Even on localhost, this introduces overhead (handshakes, packet processing). NitroCache uses Shared Memory (shm). The Rust Server manages a dedicated memory segment and handles TTL/eviction. The PHP Client maps that same memory segment into its own process