laruence/yac logo

laruence/yac

Free

A fast, lock-free, shared memory user data cache for PHP

FreeFree tier
Type
Open Source

About laruence/yac

Yac (Yet Another Cache) is a fast, lock-free, shared memory user data cache for PHP. It is designed to replace APC or local memcached. Yac stores key-value pairs in shared memory using a lockless algorithm, achieving high concurrency. It supports serialization via PHP, JSON, msgpack, or igbinary, and allows configuration of memory sizes for keys and values. Yac requires PHP 7+ and imposes limits: keys up to 48 bytes, raw values up to 64 MB, and compressed values up to 1 MB. It provides methods like Yac::set, Yac::get, and Yac::__construct with an optional key prefix. Due to its lockless nature, multiple processes modifying the same key may experience CAS competition; users should handle retries for critical writes.

Key Features

Lock-free, shared memory caching for PHP
Can replace APC or local memcached
Supports multiple serializers: PHP, JSON, msgpack, igbinary
Configurable memory sizes for keys and values
Key prefix support for grouping cache entries
TTL (time-to-live) support for cache expiration
Bulk get/set operations with arrays
CAS (compare-and-swap) write mechanism for atomicity

Pros & Cons

Pros
  • Very fast due to lockless architecture
  • Simple API similar to APC or memcached
  • Completely free and open source (BSD-style license)
  • Supports multiple serialization formats for flexibility
  • Low memory overhead with configurable slot count
Cons
  • Key length limited to 48 bytes
  • Raw value limited to 64 MB, compressed value limited to 1 MB
  • Lockless design can cause CAS competition if multiple processes write the same key
  • No built-in replication or persistence (volatile shared memory)
  • Requires careful key design to avoid CRC collisions (uses partial CRC)

Best For

Caching database query results in PHP applicationsStoring session data in shared memory across PHP processesReplacing APC cache in legacy PHP projectsLocal caching alternative to memcached when simplicity is neededCaching computed values or configuration data in high-concurrency PHP environments

FAQ

What is Yac?
Yac (Yet Another Cache) is a lock-free, shared memory user data cache for PHP. It can be used to replace APC or local memcached for caching PHP variables.
What PHP version is required?
Yac requires PHP 7 or higher.
What are the key and value size limits?
Cache keys cannot be longer than 48 bytes. Raw cache values cannot exceed 64 MB, and compressed values cannot exceed 1 MB.
How do I install Yac?
Yac can be installed from source using phpize: run '/path/to/phpize', then './configure --with-php-config=/path/to/php-config', then 'make' and 'make install'.
Does Yac support serialization?
Yes, Yac supports multiple serializers: PHP (default), JSON, msgpack, and igbinary, configurable via the yac.serializer setting.