r/PHP•
Laruenxe

Yac — Probably the fastest user data cache for PHP

Hi r/php. I'm Xinchen Hui — you might know me by my nickname, Laruence. I'm the author of Yac, Yaf and Yaconf, I used to maintain APC and Zend O+, and I was a core contributor to PHP 7 and to the PHP JIT. If there's a common thread across all of that, it's performance — pretty much everything I've worked on has been about making PHP faster, and Yac is no exception.

Today, I'd like to share Yac with you. it probably is the fastest user data cache for PHP right now. I wrote it back in 2013, when I was working at Sina Weibo — the goal was to replace the local Memcached running on our PHP machines and make PHP's local caching faster.

The design is entirely about speed. Yac keeps everything in shared memory that every PHP worker inherits across fork(), the same mechanism FPM already uses, so there's no cache server to run and no network round-trip: a get() is essentially a hash lookup, at microsecond latency. On top of that it's lockless — there's no global lock, arbitration happens per hash slot, which means throughput scales with your worker count instead of everyone queueing behind one lock.

The part that makes lockless reads safe is that integrity comes from CRC rather than from locks. Every value is checksummed on the way in and verified on the way out, so a torn or overwritten entry fails the check and comes back as a miss. The worst case in a write race is that both competing entries fail CRC and you re-fetch from your backend — Yac will never hand you wrong data. All of this rests on treating the cache as a cache rather than a database: reads vastly outnumber writes, the set of distinct keys is bounded, and a miss costs you a re-fetch, not correctness. Given that, letting readers run wide open and verifying afterwards is nearly always cheaper than serializing everyone behind a lock.

On a 16-worker benchmark sharing one cache, with a 100:1 read/write ratio, compression off and the same 160M memory budget for both backends, Yac sustains about 60M ops/s on 256-byte values where APCu manages 1.1M and a local Memcached about 0.11M. Those are throughput numbers on my machine with one workload, so please don't extrapolate them to yours — the benchmark and a reproduction script are in the repo.

If that sounds useful for your workload, give it a try: https://github.com/laruence/yac — it installs with pecl install yac or pie install laruence/yac. Issues and PRs are both welcome, and I'm happy to answer questions about the lockless design, the CRC story or the eviction policy, since those are the interesting parts.

One last thing: I also wrote a WordPress object cache plugin on top of Yac. On my own blog (www.laruence.com) it gives about a 19% QPS improvement over Memcached. If you run WordPress, it might be worth a look: https://wordpress.org/plugins/yac-object-cache/

PS: I am not a native English speaker, So I use AI to help me write this message, :), thanks.

Posted Sep 17, 2026, 3:28 AM UTC

10
Loading comments…