MongoDB Adapter (mongodb)#
Factories:
Cache::mongodb(...)MongoDbCacheAdapter::fromClient(...)(adapter-level)
Requirements:
mongodb/mongodbpackage for default client path, orinjected collection/client compatible with expected methods
Highlights:
namespace-scoped document storage
base64-encoded payload persistence
TTL-aware read-time pruning
Supported injected collection methods:
findOneupdateOnedeleteOnedeleteManycountDocuments
Example#
use Infocyph\CacheLayer\Cache\Cache;
$cache = Cache::mongodb(
'analytics',
database: 'app_cache',
collectionName: 'entries',
uri: 'mongodb://127.0.0.1:27017',
);
$cache->set('dashboard:kpi', ['orders' => 120, 'refunds' => 4], 120);