Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Implements an adapter for ext-mongodb #154

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .ci/mongodb.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extension=mongodb.so
17 changes: 15 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ env:
global:
- COMPOSER_ARGS="--no-interaction"
- COVERAGE_DEPS="php-coveralls/php-coveralls"
- EXTMONGODB_DEPS="mongodb/mongodb"
- TESTS_ZEND_CACHE_APC_ENABLED=true
- TESTS_ZEND_CACHE_APCU_ENABLED=true
- TESTS_ZEND_CACHE_FILESYSTEM_DIR=/dev/shm
Expand All @@ -25,6 +26,7 @@ env:
- TESTS_ZEND_CACHE_MEMCACHE_HOST=$TESTS_ZEND_CACHE_MEMCACHED_HOST
- TESTS_ZEND_CACHE_MEMCACHE_PORT=$TESTS_ZEND_CACHE_MEMCACHED_PORT
- TESTS_ZEND_CACHE_MONGODB_ENABLED=true
- TESTS_ZEND_CACHE_EXTMONGODB_ENABLED=true
- TESTS_ZEND_CACHE_REDIS_ENABLED=true
- TESTS_ZEND_CACHE_REDIS_HOST="127.0.0.1"
- TESTS_ZEND_CACHE_REDIS_PORT=6379
Expand All @@ -42,19 +44,22 @@ matrix:
env:
- DEPS=lowest
- APCU_PECL_VERSION="apcu-4.0.8"
- TESTS_ZEND_CACHE_EXTMONGODB_ENABLED=false
- TESTS_ZEND_CACHE_MEMCACHE_ENABLED=true
- TESTS_ZEND_CACHE_XCACHE_ENABLED=true
- php: 5.6
env:
- DEPS=locked
- LEGACY_DEPS="phpbench/phpbench phpunit/phpunit"
- APCU_PECL_VERSION="apcu-4.0.10"
- TESTS_ZEND_CACHE_EXTMONGODB_ENABLED=false
- TESTS_ZEND_CACHE_MEMCACHE_ENABLED=true
- TESTS_ZEND_CACHE_XCACHE_ENABLED=true
- php: 5.6
env:
- DEPS=latest
- APCU_PECL_VERSION="apcu-4.0.11"
- TESTS_ZEND_CACHE_EXTMONGODB_ENABLED=false
- TESTS_ZEND_CACHE_MEMCACHE_ENABLED=true
- TESTS_ZEND_CACHE_XCACHE_ENABLED=true
- php: 7
Expand All @@ -63,19 +68,22 @@ matrix:
- APCU_PECL_VERSION="apcu-5.1.2"
- APCU_BC_PECL_VERSION="apcu_bc-1.0.0"
- TESTS_ZEND_CACHE_MONGODB_USE_POLYFILL=true
- TESTS_ZEND_CACHE_EXTMONGODB_ENABLED=false
- php: 7
env:
- DEPS=locked
- LEGACY_DEPS="phpbench/phpbench phpunit/phpunit"
- APCU_PECL_VERSION="apcu-5.1.8"
- APCU_BC_PECL_VERSION="apcu_bc-1.0.2"
- TESTS_ZEND_CACHE_MONGODB_USE_POLYFILL=true
- TESTS_ZEND_CACHE_EXTMONGODB_ENABLED=false
- php: 7
env:
- DEPS=latest
- APCU_PECL_VERSION="apcu"
- APCU_BC_PECL_VERSION="apcu_bc-1.0.3"
- TESTS_ZEND_CACHE_MONGODB_USE_POLYFILL=true
- TESTS_ZEND_CACHE_EXTMONGODB_ENABLED=false
- php: 7.1
env:
- DEPS=lowest
Expand Down Expand Up @@ -158,10 +166,14 @@ install:
phpenv config-add .ci/memcached.ini ;
fi ;

if [[ $TESTS_ZEND_CACHE_MONGODB_ENABLED == 'true' && $TESTS_ZEND_CACHE_MONGODB_USE_POLYFILL != 'true' ]]; then
- if [[ $TESTS_ZEND_CACHE_MONGODB_ENABLED == 'true' && $TESTS_ZEND_CACHE_MONGODB_USE_POLYFILL != 'true' ]]; then
phpenv config-add .ci/mongo.ini ;
fi ;

- if [[ $TESTS_ZEND_CACHE_EXTMONGODB_ENABLED == 'true' ]]; then
phpenv config-add .ci/mongodb.ini ;
fi ;

- if [[ $TESTS_ZEND_CACHE_XCACHE_ENABLED == 'true' ]]; then
phpenv config-add .ci/xcache.ini ;
fi ;
Expand All @@ -171,7 +183,8 @@ install:
- if [[ $DEPS == 'latest' ]]; then travis_retry composer update $COMPOSER_ARGS ; fi
- if [[ $DEPS == 'lowest' ]]; then travis_retry composer update --prefer-lowest --prefer-stable $COMPOSER_ARGS ; fi
- if [[ $TEST_COVERAGE == 'true' ]]; then travis_retry composer require --dev $COMPOSER_ARGS $COVERAGE_DEPS ; fi
- if [[ $TESTS_ZEND_CACHE_MONGODB_USE_POLYFILL == 'true' ]]; then travis_retry composer require --dev --no-update mongofill/mongofill:dev-master ; fi
- if [[ $TESTS_ZEND_CACHE_MONGODB_USE_POLYFILL == 'true' ]]; then travis_retry composer require --dev --no-update $COMPOSER_ARGS mongofill/mongofill:dev-master ; fi
- if [[ $TESTS_ZEND_CACHE_EXTMONGODB_ENABLED == 'true' ]]; then travis_retry composer require --dev --no-update $COMPOSER_ARGS $EXTMONGODB_DEPS ; fi
- stty cols 120 && composer show
- pecl list
- php -m
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@
"ext-memcache": "Memcache >= 2.0.0 to use the Memcache storage adapter",
"ext-memcached": "Memcached >= 1.0.0 to use the Memcached storage adapter",
"ext-mongo": "Mongo, to use MongoDb storage adapter",
"ext-mongodb": "MongoDB, to use the ExtMongoDb storage adapter",
"ext-redis": "Redis, to use Redis storage adapter",
"ext-wincache": "WinCache, to use the WinCache storage adapter",
"ext-xcache": "XCache, to use the XCache storage adapter",
"mongodb/mongodb": "Required for use with the ext-mongodb adapter",
"mongofill/mongofill": "Alternative to ext-mongo - a pure PHP implementation designed as a drop in replacement"
},
"autoload": {
Expand Down
59 changes: 59 additions & 0 deletions docs/book/storage/adapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,11 @@ Name | Data Type | Default Value | Description
PHP extension [mongo](http://php.net/mongo), or a MongoDB polyfill library, such as
[Mongofill](https://github.com/mongofill/mongofill).

> #### ext-mongodb
>
> If you are using the mongodb extension (vs the mongo extension), you will need
> to use the [ExtMongoDb adapter](#the-extmongodb-adapter) instead.

This adapter implements the following interfaces:

- `Zend\Cache\Storage\FlushableInterface`
Expand Down Expand Up @@ -832,6 +837,60 @@ Key | Default | Description
`connectionOptions` | `['fsync' => false, 'journal' => true]` | Associative array of options to pass to `MongoClient` (see the [MongoClient docs](http://php.net/MongoClient)).
`driverOptions` | `[]` | Associative array of driver options to pass to `MongoClient` (see the [MongoClient docs](http://php.net/MongoClient)).

## The ExtMongoDB Adapter

- Since 2.8.0

`Zend\Cache\Storage\Adapter\ExtMongoDB` stores cache items using the mongodb extension, and
requires that the MongoDB PHP Client library is also installed. You can install the client
library using the following:

```bash
$ composer require mongodb/mongodb
```

> #### ext-mongo
>
> If you are using the mongo extension (vs the mongodb extension), you will need
> to use the [MongoDb adapter](#the-mongodb-adapter) instead.

This adapter implements the following interfaces:

- `Zend\Cache\Storage\FlushableInterface`

### Capabilities

Capability | Value
---------- | -----
`supportedDatatypes` | `string`, `null`, `boolean`, `integer`, `double`, `array`
`supportedMetadata` | _id
`minTtl` | 0
`maxTtl` | 0
`staticTtl` | `true`
`ttlPrecision` | 1
`useRequestTime` | `false`
`lockOnExpire` | 0
`maxKeyLength` | 255
`namespaceIsPrefix` | `true`
`namespaceSeparator` | <Option value of namespace_separator>

### Adapter specific options

Name | Data Type | Default Value | Description
---- | --------- | ------------- | -----------
`lib_option` | `array` | | Associative array of options where the array key is the option name.
`namespace_separator` | `string` | ":" | A separator for the namespace and prefix.

Available keys for `lib_option` include:

Key | Default | Description
--- | ------- | -----------
`server` | `mongodb://localhost:27017` | The MongoDB server connection string (see the [MongoDB\\Client docs](https://docs.mongodb.com/php-library/current/reference/method/MongoDBClient__construct/)).
`database` | `zend` | Name of the database to use; MongoDB will create this database if it does not exist.
`collection` | `cache` | Name of the collection to use; MongoDB will create this collection if it does not exist.
`connectionOptions` | `['fsync' => false, 'journal' => true]` | Associative array of URI options (such as authentication credentials or query string parameters) to pass to `MongoDB\\Client` (see the [MongoDB\\Client docs](https://docs.mongodb.com/php-library/current/reference/method/MongoDBClient__construct/)).
`driverOptions` | `[]` | Associative array of driver options to pass to `MongoDB\\Client` (see the [MongoDB\\Client docs](https://docs.mongodb.com/php-library/current/reference/method/MongoDBClient__construct/)).

## The WinCache Adapter

`Zend\Cache\Storage\Adapter\WinCache` stores cache items into shared memory
Expand Down
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
<env name="TESTS_ZEND_CACHE_MONGODB_COLLECTION" value="cache" />
<env name="TESTS_ZEND_CACHE_MONGODB_CONNECTSTRING" value="mongodb://localhost/" />
<env name="TESTS_ZEND_CACHE_MONGODB_DATABASE" value="zend_test" />
<env name="TESTS_ZEND_CACHE_EXTMONGODB_ENABLED" value="false" />
<env name="TESTS_ZEND_CACHE_EXTMONGODB_COLLECTION" value="cache" />
<env name="TESTS_ZEND_CACHE_EXTMONGODB_CONNECTSTRING" value="mongodb://localhost/" />
<env name="TESTS_ZEND_CACHE_EXTMONGODB_DATABASE" value="zend_test" />
<env name="TESTS_ZEND_CACHE_REDIS_ENABLED" value="false" />
<env name="TESTS_ZEND_CACHE_REDIS_HOST" value="127.0.0.1" />
<env name="TESTS_ZEND_CACHE_REDIS_PORT" value="6379" />
Expand Down
Loading