PHP Conference Ehime 2026

Yac

Introduction

Yac (Yet Another Cache) is a lock-free, shared memory user data cache, and can be used to replace APC or local memcached.

Yac stores data in shared memory, which makes it visible to every PHP worker of the same machine without any inter-process communication. Instead of locking, Yac relies on atomic slot updates plus a few collision probes, so a cache miss never blocks a request, and a concurrent write can at worst cause a failed store or a missed read that the caller can simply retry.

With no locks and no inter-process communication in the access path, a read is essentially a hash lookup in shared memory. As a result, Yac is extremely fast, with microsecond-level read latency, and its throughput can scale with the number of workers as long as writes are spread across keys; see the » benchmarks.

Because Yac trades correctness guarantees for speed and throughput, it is best suited for data that is expensive to produce but easy to recreate: page fragments, configuration snapshots, small service responses, and other local caches. It should not be used as the authoritative store for irreplaceable data.

As of yac 2.4.0, small scalar values — NULL, booleans, most integers (those that fit in 60 signed bits on 64-bit builds), strings of up to 7 bytes and empty arrays — are stored directly inside the hash slot instead of in a separate value block ("embedded values"), which removes the value-memory allocation and block copy on every access and significantly improves performance while reducing memory usage. Version 2.4.0 also switched the compression backend from FastLZ to LZ4, making compressed reads several times faster.

Note:

Shared memory is only visible within one machine. To share a cache across several servers, use a network cache such as Memcached or Redis instead.

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top