cache/mongodb-adapter

A PSR-6 cache implementation using MongoDB. This implementation supports tags

Maintainers

Package info

github.com/php-cache/mongodb-adapter

Homepage

pkg:composer/cache/mongodb-adapter

Transparency log

Statistics

Installs: 66 559

Dependents: 0

Suggesters: 1

Stars: 9

3.0.0 2026-08-20 01:59 UTC

This package is auto-updated.

Last update: 2026-08-20 02:25:13 UTC


README

Latest Stable Version Coverage Software License

This package provides PSR-6 and PSR-16 cache implementations backed by MongoDB. The pool also supports tags.

Installation

Install the package and enable the MongoDB extension:

composer require cache/mongodb-adapter:^3.0

Usage

use Cache\Adapter\MongoDB\MongoDBCachePool;
use MongoDB\Driver\Manager;

$manager = new Manager('mongodb://127.0.0.1:27017');
$collection = MongoDBCachePool::createCollection($manager, 'application', 'cache');
$pool = new MongoDBCachePool($collection);

createCollection() creates the TTL index used to remove expired entries.

Upgrading to version 3

Version 3 stores a generation snapshot with each tagged item and a separate marker document for each tag. Version 2 workers cannot safely share this format.

Stop or drain all workers, clear the cache collection, and then deploy version 3. Follow the same sequence before a rollback.

Contributing

Send pull requests to the main repository. Report issues on the GitHub issue tracker.