Internet Super Hero » Blog Archive » PHP: Client side caching for all MySQL extensions
This article introduces a C-based mysqlnd plugin that adds query result caching to PHP's MySQL extensions (ext/mysql, ext/mysqli, PDO_MySQL) without modifying existing APIs, operating transparently as a middleware layer between applications and the database server. Cached results can be stored in multiple backends (memory, APC, Memcache, SQLite) with configurable TTL-based invalidation, and includes a "slam defense" mechanism to prevent database overload when popular cache entries expire simultaneously. The plugin avoids the serialization overhead of PHP-based caching solutions by intercepting and replaying raw wire data at the driver level, though it only works with buffered queries and relies on SQL comments to control which queries are cached.