laminas/laminas-cache-storage-adapter-benchmark
Benchmark adapter for laminas-cache to measure cache storage performance. Wrap a cache storage to record timing and profiling data for reads/writes, helping compare adapters and spot slow operations during testing and tuning.
composer require laminas/laminas-cache-storage-adapter-benchmark — it’s a dev/test dependency, so consider --dev.Filesystem, Redis) with the Benchmark adapter to measure real overhead without changing your app logic.
$benchmarkAdapter = new \Laminas\Cache\Storage\Adapter\Benchmark(
new \Laminas\Cache\Storage\Adapter\Filesystem(['CacheDir' => '/tmp/cache'])
);
$storage = \Laminas\Cache\StorageFactory::factory($benchmarkAdapter);
$storage->setItem('key', 'val'), retrieve stats with $benchmarkAdapter->getStats() — look for write_time, read_time, count_write, count_read.config/autoload/cache.local.php, dynamically inject the benchmark adapter in dev/test only:
'caches' => [
'default' => [
'adapter' => [
'name' => 'Benchmark',
'options' => [
'adapter' => [
'name' => 'Filesystem',
'options' => ['CacheDir' => '/tmp/cache'],
],
],
],
],
],
/debug/cache route).Filesystem vs Apcu vs Redis) while keeping the benchmark wrapper — compare total_read_time, hit_ratio, and operation_count across runs.bin/benchmark-cache) to capture getStats() before/after refactoring or config tweaks, committing results to a baseline file.microtime(true) — significant overhead. Use environment guards:
if (getenv('APP_ENV') === 'dev') {
$adapter = new Benchmark($realAdapter);
} else {
$adapter = $realAdapter;
}
new Benchmark(new Benchmark($adapter))) — stats will break. Ensure only one benchmark adapter is active.getStats() returns cumulative values — reset between test runs using resetStats() (if available) or re-instantiate.__call() forwarding. Confirm edge-case calls (e.g., normalizeOptions, hasOptions) still work if customized.verbosity in your inner adapter (e.g., Filesystem::setTtl(0)) to isolate benchmark noise from backend latency.How can I help you explore Laravel packages today?