I have built TQCache as a fast and simple key-value store that can be used as a drop-in replacement for Memcached and in some cases for Redis. While surely not as mature, it does offer a specific set of trade-offs that may interest you. It is designed for workloads where both memory efficiency and persistence are priorities, such as session storage.
See: https://github.com/mevdschee/tqcache
What is TQCache?
Implemented in Go, TQCache works as both an embeddable library and a standalone
server. It speaks the Memcached protocol (both text and binary), meaning it
works out-of-the-box with existing clients, including PHP’s native memcached
session handler.
The Trade-off: Memory vs. Disk
The primary architectural difference between TQCache and its alternatives is how it stores data. Memcached stores everything in RAM and it is fast. Redis (typically) keeps the dataset in RAM for speed, periodically dumping to disk or appending to a log for persistence. TQCache keeps only the keys in RAM, while the actual values rely on the operating system’s page cache and are stored on disk (using append-only logs).
The “Niche” Advantage
This architecture makes TQCache extremely memory efficient. In benchmarks with 100,000 keys (10KB payloads), TQCache used approximately 25MB of RAM, whereas Memcached usage was ~681MB and Redis ~815MB.
If you have a dataset larger than your available RAM, TQCache allows you to serve it with reasonable performance, relying on fast SSDs/NVMe, whereas Memcached would evict keys.
Realistic Performance & Limitations
It is important to be realistic: TQCache is generally slower than in-memory solutions, especially for writes, because it prioritizes durability guarantees (or at least disk-backed storage).
TQCache achieves ~39k RPS write throughput in its periodic sync mode. Compared to Redis (~48k RPS) and Memcached (~142k RPS) it is slower. If you need massive write throughput, TQCache is likely not the right tool. On reads it performs surprisingly well, achieving ~132k RPS, which outperforms Redis (~116k RPS) but is still significantly slower than Memcached (~282k RPS).
Additionally, TQCache is a pure Key-Value store. It does not support the rich
data structures (Sets, Sorted Sets, Lists, HyperLogLogs) that make Redis so
versatile. If you use Redis for more than just SET/GET, TQCache is not a
replacement.
How it works
The storage engine is built on a robust three-level architecture designed for durability and fast recovery:
- Data Log (Disk): An append-only file that stores the actual values and their expiration metadata. This file is immutable, meaning new values are always appended to the end.
- Index Log (Disk): A smaller append-only file that stores the mapping between keys and their location (offset) in the data log.
- B-Tree (RAM): An in-memory structure that maintains the key-to-offset mapping for O(log n) lookups. This is totally rebuilt from the index log on startup.
Compaction
Since TQCache uses append-only logs, updating a key doesn’t overwrite the old data; it just adds a new entry. To prevent the disk from filling up, a compaction process runs periodically:
- It takes a snapshot of the in-memory index.
- It copies the valid (not expired, deleted or overwritten) data to a new log file.
- It performs a quick “tail copy” of any writes that happened during the process (requiring a very short lock).
- It atomically swaps the files.
When to use it?
TQCache shines as a persistent Memcached. It is fully compatible with PHP sessions. Unlike Memcached, TQCache persists sessions to disk, so you don’t lose all user logins if the service restarts. If you value storage capacity over raw microsecond latency and want to cache terabytes of data without paying for terabytes of RAM. It uses a single binary (or Go library import) with a simple append-only log format that is robust and easy to back up.
Conclusion
TQCache is not a “Redis Killer.” It is a specialized tool that creates a middle ground: it offers the protocol simplicity of Memcached with the persistence of a database, all while keeping a small memory footprint.
Disclaimer: I’ve built TQCache in one evening and it has not been tested in production, you’ve been warned!