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

Array Adapter Laravel Package

cache/array-adapter

PSR-6 cache pool implemented with an in-memory PHP array. Zero configuration: just instantiate ArrayCachePool for fast, ephemeral caching in tests or single-request use. Part of the PHP Cache ecosystem with shared docs and optional features info.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package: composer require cache/array-adapter. Then instantiate the pool directly with $pool = new Cache\ArrayAdapter\ArrayCachePool();. Its zero-configuration nature makes it perfect for:

  • Writing unit tests (e.g., mocking cache in PHPUnit without external dependencies)
  • Local development where Redis/Memcached isn’t configured yet
  • Temporary caching within a single request lifecycle (e.g., caching computed values in a CLI script)

Use standard PSR-6 methods: getItem($key), save($item), clear(), and hasItem($key).

Implementation Patterns

  • Testing Infrastructure: Use as a drop-in mock for cache-dependent services in tests — state resets automatically between tests, ensuring isolation.
  • Request-Local Caching: Cache expensive operations within one request (e.g., in a command handler or controller action) to avoid redundant computation.
  • Fallback Chain: Combine with persistent pools using Cache\Pool\ChainCachePool for graceful degradation during development — e.g., try Redis first, fall back to array if unavailable.
  • Debugging & Inspection: Call $pool->getItems() or $pool->debug() (if exposed) to introspect cached items, useful during development to verify cache hits/misses without external tools.

Gotchas and Tips

  • No Persistence: All data vanishes at request end. Never use in production — Laravel expects persistent storage (Redis, file, database), not in-memory arrays.
  • ⚠️ Memory Pressure: In long-running SAPIs (e.g., Apache mod_php) or workers (Swoole), large or uncleared caches can exhaust memory. Explicitly clear() after heavy use.
  • 🔍 Lazy Expiration: Expired items may still be returned unless you manually iterate (getItems()) or call clear() — the adapter doesn’t auto-gc during reads.
  • 🔄 Non-Thread-Safe: Each PHP process has its own array — useless for shared caching across workers (e.g., Horizon workers, Swoole coroutines).
  • 📦 PSR-6 vs PSR-16: Laravel uses PSR-16 (Cache::remember()), not PSR-6. This adapter won’t plug in to Laravel’s native Cache facade without a bridge — better suited for PSR-6-aware libraries or custom test harnesses.
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