For data such as a category tree or an API response you need a data cache. APCu keeps values in one FPM master's shared memory, shared by that pool's workers only and emptied when FPM restarts. Redis 2,763 and Memcached 4,600 are network servers that every web server and the CLI can share. Ubuntu 26.04 225 ships php8.5-apcu (APCu 5.1.24), php8.5-redis (phpredis 6.2.0 10,226 ), php8.5-memcached and redis-server 8.0.5.
<?php
$product = ['id' => 42, 'name' => 'Deluxe Kettle', 'price' => 39.90, 'tags' => range(1, 20)];
apcu_store('product:42', $product, 300); // key, value, TTL in seconds
$redis = new Redis();
$redis->connect('127.0.0.1', 6422); // a test Redis; the default is 6379
$redis->set('product:42', serialize($product), ['EX' => 300]);
$time = function (string $label, callable $read): void {
$start = hrtime(true);
for ($i = 0; $i < 20_000; $i++) {
$read();
}
printf("%-6s %6.2f us per read\n", $label, (hrtime(true) - $start) / 20_000 / 1000);
};
$time('APCu', fn(): array => apcu_fetch('product:42'));
$time('Redis', fn(): array => unserialize($redis->get('product:42')));Run with php -d apc.enable_cli=1 cache.php, since APCu is off in the CLI by default:
APCu 0.91 us per read Redis 112.49 us per read
APCu was over 100 times faster because each Redis read crosses a socket. Redis is still far cheaper than the query it replaces, and several servers can share it, with persistence and data types, so it is the usual home for sessions and queues. Memcached is a simpler, multi-threaded cache with no persistence. Redis 8 is licensed under AGPLv3 among other options; Valkey 251,210 is its BSD-licensed fork.