An open API service indexing awesome lists of open source software.

https://github.com/zircote/zend_cache_backend_mongodb

A Zend Framework Extended Cache Backend for MongoDb
https://github.com/zircote/zend_cache_backend_mongodb

Last synced: 8 months ago
JSON representation

A Zend Framework Extended Cache Backend for MongoDb

Awesome Lists containing this project

README

          

# Zend_Cache_Backend_MongoDb

### Notes:
* do not attempt to use MongoDb as a cache store with a capped collection
* see: http://www.mongodb.org/display/DOCS/Capped+Collections#CappedCollections-UsageandRestrictions
* Requires mongodb version >= 2.0

#### Create the collection and indexes

```javascript
var database_name = "zend_cache";
var collection = "etags";

use database_name;
db.createCollection(collection);
db.getCollection(collection).ensureIndex({"tags" : true});
db.getCollection(collection).ensureIndex({"expire" : true});
db.getCollection(collection).ensureIndex({"mtime" : true});
db.getCollection(collection).getIndexes();
```

Class Instantiation:

```php
7200,
'automatic_serialization' => true
);
$backendOptions = array(
'database_name' => 'zend_cache',
'collection' => 'cache'
);
$cache = Zend_Cache::factory('Core', 'MongoDb', $frontendOptions, $backendOptions);
$cache->save($data, $id, array('tag1','acct_id:1234');
$data = $cache->load($id);
```
With example methods:

```php
'zend_cache',
'database_urn' => 'mongodb://localhost:27717'
'collection' => 'cache')
);
$cache->getTags();
$cache->getIds();
$cache->getIdsMatchingAnyTags();
$cache->getIdsMatchingTags(array('tag1','tag2'));
$cache->getIdsNotMatchingTags(array('tag1','tag2'));
$cache->getMetadatas($id);
```

## Zend_Config_Ini

```php
resources.cachemanager.mongodb.frontend.name = Core
resources.cachemanager.mongodb.frontend.customFrontendNaming = false
resources.cachemanager.mongodb.frontend.options.lifetime = 7200
resources.cachemanager.mongodb.frontend.options.automatic_serialization = true
resources.cachemanager.mongodb.backend.name = MongoDb
resources.cachemanager.mongodb.backend.customBackendNaming = false
resources.cachemanager.mongodb.backend.options.database_name = "zend_cache"
resources.cachemanager.mongodb.backend.options.collection = "cache"
resources.cachemanager.mongodb.frontendBackendAutoload = false

hasResource('cachemanager')){
$cache = $bootstrap->getResource('cachemanager')->getCache('mongodb');
$cache->load($id);
}
```

#### Tests Status:

```
[ zircote ~/Workspace/ZendFramework/tests/Zend/Cache ] phpunit MongoDbBackendTest.php
PHP Warning: Xdebug MUST be loaded as a Zend extension in Unknown on line 0
PHPUnit 3.6.10 by Sebastian Bergmann.

..........................................

Time: 1 second, Memory: 4.00Mb

OK (42 tests, 96 assertions)
```