laminas/laminas-cache-storage-adapter-ext-mongodb
objectId metadata).cache:page directive).Adopt if:
mongodb/mongodb PHP extension) and you need a caching layer without adding Redis/Memcached.Illuminate/Cache (via adapter compatibility).objectId for cache items to correlate with MongoDB documents).Look elsewhere if:
For Executives: "This package lets us leverage our existing MongoDB infrastructure for caching, reducing operational overhead by eliminating Redis/Memcached. It’s ideal for [use case, e.g., ‘scaling our API response times’ or ‘consolidating our data layer’], with minimal dev effort. Since it’s part of the Laminas ecosystem, it’s battle-tested and aligns with our PHP stack. The trade-off is slightly higher latency (~2–5x Redis), but the cost savings and simplicity justify it for [specific workload]."
For Engineering:
"This adapter bridges Laminas Cache (or Laravel’s cache) with MongoDB’s ext-mongodb driver, offering:
cache()->forgetByTag('user:123')).Cache facade via Laminas\Cache\Storage\Adapter\MongoDb wrapper.objectId for cache items to link to source documents).
Pros: No new infrastructure. Cons: Slower than Redis (~5–10ms vs. ~1ms). Best for read-heavy or data-consistency-critical workloads. Let’s prototype it for [specific feature] and compare perf with Redis."For Developers: "To use this:
composer require laminas/laminas-cache-storage-adapter-ext-mongodb.mongodb://user:pass@host:port/db).use Laminas\Cache\Storage\Adapter\ExtMongoDb;
$adapter = new ExtMongoDb([
'resourceManager' => new \MongoDB\Driver\Manager('mongodb://...'),
'collection' => 'cache_items',
'ttl' => 7200, // 2 hours
]);
Works with Laravel via Cache::extend('mongodb', fn() => $adapter).
Key gotchas: Ensure your MongoDB collection has a TTL index ({ "expiresAt": 1 }), and monitor cache hit ratios—this isn’t a drop-in Redis replacement."
How can I help you explore Laravel packages today?