- do not attempt to use MongoDb as a cache store with a capped collection
- Requires mongodb version >= 2.0
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
$frontendOptions = array(
'lifetime' => 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
$cache = new Zend_Cache_Backend_MongoDb(
array('database_name' => '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);
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
<?php
if($bootstrap->hasResource('cachemanager')){
$cache = $bootstrap->getResource('cachemanager')->getCache('mongodb');
$cache->load($id);
}
[ 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)