A new LRU cache implementation for PHP 8.5 achieves over 15.4 million operations per second on a standard laptop running in a Docker environment. The developer designed this solution as a foundation for an Identity Map layer within a persistence layer built on Eloquent.
The architecture relies on flat integer-indexed arrays instead of objects to reduce memory allocation and improve CPU cache locality. By using object pooling, the system avoids new memory allocations after the initial population, ensuring consistent performance.
The implementation utilizes readonly properties and final classes to assist the JIT compiler with devirtualization and method inlining. These optimizations allow the JIT to treat complex logic as direct memory access, significantly reducing latency.
The cache structure separates responsibilities into specialized classes: LruNodePool for ID management, LruNodeKeys for mapping, and LruNodeLinks for the doubly linked list. This modular approach ensures that the JIT compiler can optimize hot paths effectively.
The developer estimates that the throughput could reach 25–30 million operations per second on production hardware. This performance level aims to remove the cache overhead from the application's critical path, shifting the bottleneck back to database interactions.






