Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laminas Cache Storage Adapter Benchmark Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install: Run composer require laminas/laminas-cache-storage-adapter-benchmark — it’s a dev/test dependency, so consider --dev.
  2. First use case: Wrap your existing cache adapter (e.g., 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);
    
  3. Check metrics: After using $storage->setItem('key', 'val'), retrieve stats with $benchmarkAdapter->getStats() — look for write_time, read_time, count_write, count_read.

Implementation Patterns

  • Configuration-driven benchmarking: In 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'],
                    ],
                ],
            ],
        ],
    ],
    
  • Profiling middleware: Use the benchmark adapter inside a PSR-15 or Expressive-style middleware to log per-request cache metrics (e.g., in a debug toolbar or /debug/cache route).
  • Side-by-side comparisons: Swap underlying adapters (e.g., Filesystem vs Apcu vs Redis) while keeping the benchmark wrapper — compare total_read_time, hit_ratio, and operation_count across runs.
  • Automated baselining: Run CLI benchmarks (e.g., bin/benchmark-cache) to capture getStats() before/after refactoring or config tweaks, committing results to a baseline file.

Gotchas and Tips

  • ⚠️ Never use in production: The adapter wraps every call in microtime(true) — significant overhead. Use environment guards:
    if (getenv('APP_ENV') === 'dev') {
        $adapter = new Benchmark($realAdapter);
    } else {
        $adapter = $realAdapter;
    }
    
  • Nested adapters: Avoid double-wrapping (new Benchmark(new Benchmark($adapter))) — stats will break. Ensure only one benchmark adapter is active.
  • Metrics granularity: getStats() returns cumulative values — reset between test runs using resetStats() (if available) or re-instantiate.
  • Integration gotcha: The benchmark adapter does not implement all storage interface methods explicitly — rely on __call() forwarding. Confirm edge-case calls (e.g., normalizeOptions, hasOptions) still work if customized.
  • Debug tip: Enable verbosity in your inner adapter (e.g., Filesystem::setTtl(0)) to isolate benchmark noise from backend latency.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport