Skip to content

cjaentsch/Zend_Cache_Backend_MongoDb

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Zend_Cache_Backend_MongoDb

Notes:

Create the collection and indexes

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);

Zend_Config_Ini

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);
}

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)

Releases

No releases published

Packages

No packages published